You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/12-while-for/article.md
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,7 @@ A single execution of the loop body is called *an iteration*. The loop in the ex
33
33
34
34
If there were no `i++` in the example above, the loop would repeat (in theory) forever. In practice, the browser provides ways to stop such loops, and for server-side JavaScript we can kill the process.
35
35
36
-
Any expression or a variable can be a loop condition, not just a comparison. They are evaluated and converted to boolean by `while`.
36
+
Any expression or a variable can be a loop condition, not just a comparison. They are evaluated and converted to a boolean by `while`.
37
37
38
38
For instance, the shorter way to write `while (i != 0)` could be `while (i)`:
39
39
@@ -227,7 +227,7 @@ while (true) {
227
227
alert( 'Sum: '+ sum );
228
228
```
229
229
230
-
The `break` directive is activated in the line `(*)` if the user enters an empty line or cancels the input. It stops the loop immediately, passing the control to the first line after the loop. Namely, `alert`.
230
+
The `break` directive is activated at the line `(*)` if the user enters an empty line or cancels the input. It stops the loop immediately, passing the control to the first line after the loop. Namely, `alert`.
231
231
232
232
The combination "infinite loop + `break` as needed" is great for situations when the condition must be checked not in the beginning/end of the loop, but in the middle, or even in several places of the body.
233
233
@@ -266,11 +266,11 @@ for (let i = 0; i < 10; i++) {
266
266
267
267
From a technical point of view it's identical to the example above. Surely, we can just wrap the code in the `if` block instead of `continue`.
268
268
269
-
But as a side-effect we got one more figure brackets nesting level. If the code inside `if` is longer than a few lines, that may decrease the overall readability.
269
+
But as a side-effect we got one more nesting level (the `alert` call inside the curly braces). If the code inside `if` is longer than a few lines, that may decrease the overall readability.
270
270
````
271
271
272
272
````warn header="No `break/continue` to the right side of '?'"
273
-
Please note that syntax constructs that are not expressions cannot be used in `'?'`. In particular, directives `break/continue` are disallowed there.
273
+
Please note that syntax constructs that are not expressions cannot be used with the ternary operator `?`. In particular, directives such as `break/continue` are disallowed there.
274
274
275
275
For example, if we take this code:
276
276
@@ -292,7 +292,7 @@ if (i > 5) {
292
292
...Then it stops working. The code like this will give a syntax error:
293
293
294
294
295
-
That's just another reason not to use a question mark operator `'?'` instead of `if`.
295
+
That's just another reason not to use a question mark operator `?` instead of `if`.
296
296
````
297
297
298
298
## Labels for break/continue
@@ -385,4 +385,4 @@ To make an "infinite" loop, usually the `while(true)` construct is used. Such a
385
385
386
386
If we don't want to do anything on the current iteration and would like to forward to the next one, the `continue` directive does it.
387
387
388
-
`Break/continue` support labels before the loop. A label is the only way for `break/continue` to escape the nesting and go to the outer loop.
388
+
`break/continue` support labels before the loop. A label is the only way for `break/continue` to escape the nesting and go to the outer loop.
0 commit comments