Which values get shown by the "for" loop?
For each loop write down which values it is going to show. Then compare with the answer.
alert same values or not?
The postfix form:
for (let i = 0; i < 5; i++) alert( i );
The prefix form:
for (let i = 0; i < 5; ++i) alert( i );
The answer: from
4 in both cases.
That can be easily deducted from the algorithm of
- Execute once
i=0before everything (begin).
- Check the condition
true– execute the loop body
alert(i), and then
i++ is separated from the condition check (2). That’s just another statement.
The value returned by the increment is not used here, so there’s no difference between