Looping Problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Looping Problem

for(var i=0;i<=10;i+=2){ } document.write(i); i know the answer is 12, but when i try this : for(var i=0;i<=10;i+=3){ } document.write(i); why i still 12 ??

5th Mar 2017, 2:21 PM
AryaJ
AryaJ - avatar
2 Answers
+ 14
Because the iterator is incremented like this: 0, 3, 6, 9, 12 - oh, not smaller than or equal to 10 anymore, time to leave the loop.
5th Mar 2017, 2:38 PM
Tashi N
Tashi N - avatar
+ 9
Because 12 is the first multiple of both 3 and 2 to be greater than 9...
5th Mar 2017, 6:55 PM
visph
visph - avatar