This commit is contained in:
Ilya Kantor 2015-09-02 23:00:53 +02:00
parent 835d2ae1ce
commit f3886cfb79
2 changed files with 11 additions and 10 deletions

View file

@ -1,4 +1,4 @@
Ответ: `1`. The answer: `1`.
```js ```js
//+ run //+ run
@ -9,18 +9,19 @@ while (i) {
} }
``` ```
Каждое выполнение цикла уменьшает `i`. Проверка `while(i)` даст сигнал "стоп" при `i = 0`. 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 ("unrolled"):
```js ```js
var i = 3 var i = 3;
alert( i-- ); // выведет 3, затем уменьшит i до 2
alert(i--) // выведет 2, затем уменьшит i до 1 alert(i--); // shows 3, decreases i to 2
alert(i--) // выведет 1, затем уменьшит i до 0 alert(i--) // shows 2, decreases i to 1
// все, проверка while(i) не даст выполняться циклу дальше alert(i--) // shows 1, decreases i to 0
// done, while(i) check stops the loop
``` ```

View file

@ -1,8 +1,8 @@
# Последнее значение цикла # Last loop value
[importance 3] [importance 3]
Какое последнее значение выведет этот код? Почему? What is be the last value alerted by this code? Why?
```js ```js
var i = 3; var i = 3;