en.javascript.info/1-js/2-first-steps/13-while-for/1-loop-last-value/solution.md
Ilya Kantor 88bd9889a2 work
2016-05-26 12:43:54 +03:00

432 B

The answer: 1.

let i = 3;

while (i) {
  alert( i-- );
}

Every loop iteration decreases i by 1. The check while(i) stops the loop when i = 0.

Hence, the steps of the loop make the following sequence ("loop unrolled"):

let i = 3;

alert(i--); // shows 3, decreases i to 2

alert(i--) // shows 2, decreases i to 1

alert(i--) // shows 1, decreases i to 0

// done, while(i) check stops the loop