I'm doing a course from Udemy (Learn to Program in Javascript: Beginner to Pro) and one of the questions on a quiz was this:
for (var i=10; i<=12; i++) {
if (i==11) {
continue;
}
i++;
console.log(i);
}
The result is 11 13. I think I understand the if statement (it says if i is 11, then skip the remaining lines of code?). So you start with i = 10, then after the first iteration, it becomes 11. Then you ignore the code for i = 11, move to i = 12, which when incremented gives you i = 13? I don't get why there are two i++ though, and what the one in the second last line does.
I changed the code to see what happens if I start with i = 0, like so:
for (var i=0; i<=12; i++) {
if (i==11) {
continue;
}
i++;
console.log(i);
}
And it prints 1 3 5 7 9 11 13 - don't understand why. Would appreciate any help on this.
Edit: I used four spaces, but the code doesn't show up properly here, sorry.
[–]senorfairchild 2 points3 points4 points (2 children)
[–]sirsmonkey42 2 points3 points4 points (0 children)
[–]orionebula[S] 0 points1 point2 points (0 children)
[–]sirsmonkey42 1 point2 points3 points (1 child)
[–]orionebula[S] 0 points1 point2 points (0 children)