work
This commit is contained in:
parent
7f1283bdbc
commit
6522852dc7
97 changed files with 75 additions and 4221 deletions
|
@ -1,26 +0,0 @@
|
|||
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 make 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
|
||||
```
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
importance: 3
|
||||
|
||||
---
|
||||
|
||||
# Last loop value
|
||||
|
||||
What is be the last value alerted by this code? Why?
|
||||
|
||||
```js
|
||||
let i = 3;
|
||||
|
||||
while (i) {
|
||||
alert( i-- );
|
||||
}
|
||||
```
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue