0

I'm working on my program when I tried a for loop with a predefined integer.

int row = 0;
[...]
//row = 50
for(row = 0; row < y; row++)
{
    [...]
}

For whatever reason, even if I specify that "row = 0;" before the while loop the code just doesn't give a sensible output. This however works just fine:

for(int temprow = 0; temprow < y; temprow++)
{
    row = temprow;
    [...]
}

What gives?

glee8e
  • 6,180
  • 4
  • 31
  • 51
Omricon
  • 1
  • 1
  • Why do you need a for? Try to use WHILE! I think so it is the better option to your case! – RMH May 25 '17 at 17:45
  • Just used to using a for loop when knowing the amount of times it should run. Habit I guess. – Omricon May 25 '17 at 17:47
  • 3
    What do you mean by _the code just doesn't give a sensible output_. What output do you expect and what output do you get? – apilat May 25 '17 at 17:55
  • Well I'm working on a maze solver, I made one previously, however I'm trying to optimise it and improve on it. This part of the code is for initialising the maze. However the first line only adds exit nodes, rather than nodes throughout the entire maze, which baffles me. – Omricon May 26 '17 at 00:38
  • This looks a bit like an XY problem: https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem. I am pretty sure what you have distilled out is not the real problem. – Henry May 26 '17 at 04:57

0 Answers0