I cam across the following function in javascript:
for (var number = 0; number <= 12; number = number + 2)
show(number);
The Output is the following
0
2
4
6
8
10
12
I expected it to be
2
4
6
8
10
12
14
Why is the “0” shown first and not “2” since the “number = number + 2″comes before the “show(number);”?
This because the order of the loop is like this:
and then 2-4 again until the condition is false, if so exits the loop.
the for loop translate to something like this:
In general for loop always work like this:
translates to: