@@ -17,7 +17,7 @@ while (condition) {
1717}
1818```
1919
20- While the ` condition ` is ` true ` , the ` code ` from the loop body is executed.
20+ While the ` condition ` is truthy , the ` code ` from the loop body is executed.
2121
2222For instance, the loop below outputs ` i ` while ` i < 3 ` :
2323
@@ -47,8 +47,8 @@ while (i) { // when i becomes 0, the condition becomes falsy, and the loop stops
4747}
4848```
4949
50- ```` smart header="Brackets are not required for a single-line body"
51- If the loop body has a single statement, we can omit the brackets `{…}`:
50+ ```` smart header="Curly braces are not required for a single-line body"
51+ If the loop body has a single statement, we can omit the curly braces `{…}`:
5252
5353```js run
5454let i = 3;
@@ -84,7 +84,7 @@ This form of syntax should only be used when you want the body of the loop to ex
8484
8585## The "for" loop
8686
87- The ` for ` loop is the most commonly used loop.
87+ The ` for ` loop is more complex, but it's also the most commonly used loop.
8888
8989It looks like this:
9090
@@ -111,8 +111,8 @@ Let's examine the `for` statement part-by-part:
111111| body | ` alert(i) ` | Runs again and again while the condition is truthy. |
112112| step| ` i++ ` | Executes after the body on each iteration. |
113113
114-
115114The general loop algorithm works like this:
115+
116116```
117117Run begin
118118→ (if condition → run body and run step)
@@ -121,6 +121,8 @@ Run begin
121121→ ...
122122```
123123
124+ That is, ` begin ` executes once, and then it iterates: after each ` condition ` test, ` body ` and ` step ` are executed.
125+
124126If you are new to loops, it could help to go back to the example and reproduce how it runs step-by-step on a piece of paper.
125127
126128Here's exactly what happens in our case:
@@ -289,8 +291,7 @@ if (i > 5) {
289291(i > 5) ? alert(i) : *!*continue*/!*; // continue isn't allowed here
290292```
291293
292- ...it stops working. Code like this will give a syntax error:
293-
294+ ...it stops working: there's a syntax error.
294295
295296This is just another reason not to use the question mark operator `?` instead of `if`.
296297````
@@ -357,12 +358,12 @@ for (let i = 0; i < 3; i++) { ... }
357358
358359The ` continue ` directive can also be used with a label. In this case, code execution jumps to the next iteration of the labeled loop.
359360
360- ```` warn header="Labels are not a \" goto \" "
361+ ```` warn header="Labels do not allow to \" jump \" anywhere "
361362Labels do not allow us to jump into an arbitrary place in the code.
362363
363364For example, it is impossible to do this:
364365```js
365- break label; // jumps to label? No.
366+ break label; // doesn't jumps to the label below
366367
367368label: for (...)
368369```
0 commit comments