Please explain why int j doesnt get (j++) at first loop ?????
The program runs correctly i just dont understand why on first loop int j doesnt get j++
When i run debug i see the following steps.
Outer loop passes to inner loop and it prints first 8
then goes to line 4
comes back to line 1 ( at this point int i becomes 1, BUT int j DOESNT GET INCREASED BY 1 as i thought it should because of j++)
goes to line 3 again (prints 8 in a new row)
goes back to line 2 (ONLY NOW int j INCREASES BY 1)
for (int i = 0; i < 10; i++) {
for (int j = 0; j <= i; j++) {
System.out.print('8'); }
System.out.println(); }
}
}
according to this diagram j++ should add increment before it loops again or eixit the loop, sorry guys but non of you explanaition cleared it out for me im still confused why j++ doesnt add 1 after it exits the loop.
Anonymous #11045644 says that inner loop with j doesnt run at first repetition. BUT it runs !
i see in debug mode it runs and prints 8, then it goes back to line 2 and here where i expect j++ to increase j and make it j=1 according to this diagram. it would make sense, since j wont be = to i and loop will exit and will go to line 4. BUT loop either way exists and goes to line 4 without j++, thus loop should be considered TRUE and keep looping, but its not.
For example in this similar code, my logic works. After first 8 is printed the loop goes back to line 4 and j++ start working, thus j gets increased by 1.
in picture 2 it print 8 and goes back to loop (line 8)
where i expet j++ to work and increase j by 1.
But it jumps out of inner loop and goes to line 10 in picture 3