Why do the right side (X) repeat itself twice? Shouldn't the second value of x be 3?
This is how i came to this conclusion: When X leaves the for loop for the first time, it gets incremented to 1. Then it enters the If statement, which increments the X value to X ( ok now im confused
As for the left side (Y) I understand as far as the second output, but why does it output 4 again?
I'm slightly confused by your expanation, because X is the left side and Y is the right side according to that code.
- Each y loop starts at 4 and reduces y until y is 2 - so it will output 4 and 3 on each loop.
- The x loop would count 0, 1, 2, 3, but because of the if statement it skips 2, and so counts 0, 1, 3.
Put them together, and you get the output you've given. Does that make sense?
Joined: Oct 24, 2009
Thank you for your reply!
I accidently mixed up the left and right sides
I understand it a little better now. I got why Y keeps repeating 3-4-3-4.
But I'm still not sure about X. I know I'm missing something, Its probably stupid but why does it repeat twice before each increment