0
Loop
In for(i=4; i<8; i++) { if (i == 6) { continue; } sum += i; } does it execute i++ first or the code block first?
6 Answers
+ 5
Yes. Step by step, your example will do:
i set to 4
i is less than 8 so do the code block, then increment i ( so i is now 5 )
i is less than 8 so do the code block, then increment i ( so i is now 6 )
i is less than 8 so do the code block, then increment i ( so i is now 7 )
i is less than 8 so do the code block, then increment i ( so i is now 8 )
i is not less than 8, so don't do the code block and jump after...
but in the code block there's first a conditional "continue" statement: so when i is equal to 6, the last part of the code block is not executed (sum += i) ;)
+ 3
The code block first
+ 2
first i is set to 4 and code block executes then i value increments till the condition i<8
once the condition fails execution of for loop is completed
+ 2
The for parenthesis parameters is semi-colon separated in three parts: for (<initialisation>; <condition>; <end loop code>)...
<initialisation> is done once, before starting the loop, and never repeated, and usualy is used to initialize a counter.
<condition> is tested at each iteration, before starting code block execution, and exit/jump after the loop code block if false.
<end loop code> is done at each iteration end (after code block execution), and is usualy used to increment or decrement the counter.
+ 1
Thx
0
So it will set i to 4, check to see if it's less than 8, do the code block, increment i by 1, and then do the whole thing again except for the part i = 4?