# How to understand a for loop?

+1 vote
There is a cycle
for (var number = 0; number <= 12; number = number + 2) <br/>console.log(number);
// → 0
// → 2

Why the first number is 0 and not 2 can pliz explain the working of a for loop that would be understandable even to an idiot.
Because I used to think that the cycle works well.
1.per. n = 0;
2.n < 12 then n+2;
3.Output n (n = 2);
and so on.
Thanks in advance.

Right now, 10 min thought and I had the suspicion that it works so
1.per. n = 0;
2. n < 12;
3 the next step is not number = number + 2; console.log;
Am I right?
All right, after all increase increment proishodit at the end of this passage. So the first is 0 and so on up to 12.

## 2 Answers

0 votes
by

Best answer
The third part of the cycle `number = number + 2`is executed after the loop body. And since the variable you initialized to zero, then in the first iteration zero in the log and displayed.
+8 votes
by
Standard scan loop
``// for (i = 0; i < N; i++) { body }    i = 0;    goto check;loop:    body;    i++;check:    if (i < N) goto loop;``