@@ -21,7 +21,7 @@ while (condition) {
21
21
22
22
While the ` condition ` is ` true ` , the ` code ` from the loop body is executed.
23
23
24
- For instance, the loop below outputs ` i ` while ` i< 3 ` :
24
+ For instance, the loop below outputs ` i ` while ` i < 3 ` :
25
25
26
26
``` js run
27
27
let i = 0 ;
@@ -37,7 +37,7 @@ If there were no `i++` in the example above, the loop would repeat (in theory) f
37
37
38
38
Any expression or a variable can be a loop condition, not just a comparison. They are evaluated and converted to boolean by ` while ` .
39
39
40
- For instance, the shorter way to write ` while (i!= 0) ` could be ` while (i) ` :
40
+ For instance, the shorter way to write ` while (i != 0) ` could be ` while (i) ` :
41
41
42
42
``` js run
43
43
let i = 3 ;
@@ -108,8 +108,8 @@ Let's examine the `for` statement part by part:
108
108
109
109
| part | | |
110
110
| -------| ----------| ----------------------------------------------------------------------------|
111
- | begin | ` i= 0 ` | Executes once upon entering the loop. |
112
- | condition | ` i< 3 ` | Checked before every loop iteration, if fails the loop stops. |
111
+ | begin | ` i = 0 ` | Executes once upon entering the loop. |
112
+ | condition | ` i < 3 ` | Checked before every loop iteration, if fails the loop stops. |
113
113
| step| ` i++ ` | Executes after the body on each iteration, but before the condition check. |
114
114
| body | ` alert(i) ` | Runs again and again while the condition is truthy |
115
115
@@ -192,7 +192,7 @@ for (; i < 3;) {
192
192
}
193
193
```
194
194
195
- The loop became identical to ` while (i< 3) ` .
195
+ The loop became identical to ` while (i < 3) ` .
196
196
197
197
We can actually remove everything, thus creating an infinite loop:
198
198
@@ -324,7 +324,7 @@ The ordinary `break` after `input` would only break the inner loop. That's not s
324
324
325
325
A * label* is an identifier with a colon before a loop:
326
326
``` js
327
- labelName: for (... ) {
327
+ labelName: for (... ) {
328
328
...
329
329
}
330
330
```
@@ -369,7 +369,7 @@ For example, it is impossible to do this:
369
369
```js
370
370
break label; // jumps to label? No.
371
371
372
- label: for(...)
372
+ label: for (...)
373
373
```
374
374
375
375
The call to a `break/continue` is only possible from inside the loop, and the label must be somewhere upwards from the directive.
@@ -381,7 +381,7 @@ We covered 3 types of loops:
381
381
382
382
- ` while ` -- The condition is checked before each iteration.
383
383
- ` do..while ` -- The condition is checked after each iteration.
384
- - ` for(;;) ` -- The condition is checked before each iteration, additional settings available.
384
+ - ` for (;;) ` -- The condition is checked before each iteration, additional settings available.
385
385
386
386
To make an "infinite" loop, usually the ` while(true) ` construct is used. Such a loop, just like any other, can be stopped with the ` break ` directive.
387
387
0 commit comments