+ 1
Js loop problem
how result is 25 when loop cant be greater than 24 var i =1; for(; i < 24; i+=3){ } console.log(i) //25
3 Answers
+ 3
because 22 is less than 24 so when it adds 3 it automatically goes to 25. It goes by 3's, but it wont refrain from skipping over the maximum- itll just stop after it has gone over it
+ 3
Remember that for every iteration of the loop, (except the first of course) the counter variable ( in this case var i) is incremented first before checking the condition. So after the 7th iteration, i becomes 22. Then for the next iteration, 3 is added to make it 25 then the condition is checked which now evaluates to false.
0
According to the condition (i<24) the loop should terminate when i becomes greater than 24
That is i = 25 which is according to the incrementation