Hello! In the Loops II there’s a mini quiz about classic for loops with the loop being as follows: (var i = 0, i < 5, i + 1). The question is “what will be the output”, and the correct answer appears as 0, 1, 2, 3, 4. My question is: in the last loop where i is less than 5, i would be equal to 4. Wouldn’t that accept the loop to go forward with the i + 1 and make the last number printed 5, and stop the loop after that?
Thanks
1 Like
The loop says “Print the number only if it’s less than 5”
That means it stops printing as soon as i is 5
2 Likes
Hey there, I think there’s an error on your code. It says:
for (var i = 0; i < 5; i + 1) while it should be
for (var i = 0; i < 5; i = i + 1) or
for (var i = 0; i < 5; i += 1) or
for (var i = 0; i < 5; i++).
Hope this helps!
Another suggestion:
for (var i of [0, 1, 2, 3, 4])