en.javascript.info/1-js/02-first-steps/12-while-for/1-loop-last-value/solution.md
Ilya Kantor 0fcf9f84fa fixes
2017-03-24 17:28:37 +03:00

25 lines
431 B
Markdown

The answer: `1`.
```js run
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 form the following sequence ("loop unrolled"):
```js
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
```