0
Explain how the for loop condition work for this code!?
5 Réponses
+ 2
Your x starts with the value 0.
1st case: 0 <= 10 is true so 0.
Then x is incremented by 3.
2nd case: 3 <= 10 is true so 3.
Then x is incremented by 3.
3rd case: 6 <= 10 is true so 6.
Then x is incremented by 3.
4th case: 9 <= 10 is true so 9.
Then x is incremented by 3.
5th case: 12 <= 10 is false so the loop breaks and the control is transferred to the end.
So output is 0 3 6 9.
+ 2
Flow of for loop -
1) Initialization
2) Condition checking
3) Code inside for is executed
4) Increment/ Decrement
+ 2
Yes, initialization is just a one time thing and the value is just updated after each iteration.
0
So we should take only the output values for the first starting value and then we should use in that condition which is given in the loop!?