0
Why?,when ++i is inside the bracket then it only print the expected value. But when ++i is in curly bracket it prints unexpected
5 Réponses
+ 2
Felipe BF yes u told right,. but if the condition become false then it stop. And when the value is let 4 (when I<5) then the condition is true, I.e 4<5 then it will increase and print 5 but,why only print until 4?
+ 1
You've got "++i" twice inside the for, and before showing its value.
This basically adds 2 to "i" every time the loop runs. As the breaking condition is "i <5", this process only occurs twice.
As for the start at 3: as "i" is initialized to 1, and then incremented twice before the "println", once we reach printing to console, "i" now is 3.
+ 1
Let If the condition is I<5, I=0, after initialization the value of I comes to condition and then increment or decriment and then print. Then why after the value of I become 4 don't increment?And only print 4.
0
Amit
It prints until 4 because the next time it wants to print, "i" doesn't fulfill the condition.
If i = 4, it'll print "6" due to the increments done inside the loop. Next time it tries to look again, it realizes "6 < 5" is false, so the loop breaks.
0
https://code.sololearn.com/cuiE71qYdSbF/?ref=app
In this 4<5 then condition is true, so the value of "I" transfer to increment and inside the curly bracket, and then print function will work,but don't happen.
https://code.sololearn.com/cuiE71qYdSbF/?ref=app