This commit is contained in:
Ilya Kantor 2017-03-24 17:28:37 +03:00
parent c9401b3104
commit 0fcf9f84fa
58 changed files with 673 additions and 643 deletions

View file

@ -11,7 +11,7 @@ The task demonstrates how postfix/prefix forms can lead to different results whe
Then follow `2,3,4…` -- the values show up one after another. The comparison always uses the incremented value, because `++` is before the variable.
Finally, `i=4` is incremented to `5`, the comparison `while(5 < 5)` fails and the loop stops. So `5` is not shown.
Finally, `i=4` is incremented to `5`, the comparison `while(5 < 5)` fails, and the loop stops. So `5` is not shown.
2. **From 1 to 5**
```js run
@ -28,4 +28,3 @@ The task demonstrates how postfix/prefix forms can lead to different results whe
Let's stop on `i=4`. The prefix form `++i` would increment it and use `5` in the comparison. But here we have the postfix form `i++`. So it increments `i` to `5`, but returns the old value. Hence the comparison is actually `while(4 < 5)` -- true, and the control goes on to `alert`.
The value `i=5` is the last one, because on the next step `while(5 < 5)` is false.

View file

@ -4,9 +4,9 @@ importance: 4
# Which values shows the while?
For every loop, scribe down which values it shows, in your opinion.
For every loop, write down which values it shows, in your opinion. And then compare with the answer.
And then compare with the answer.
Both loops `alert` same values or not?
1. The prefix form `++i`:
@ -20,4 +20,3 @@ And then compare with the answer.
let i = 0;
while (i++ < 5) alert( i );
```