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
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@ while (i < 3) { // shows 0, then 1, then 2
31
31
32
32
A single execution of the loop body is called *an iteration*. The loop in the example above makes three iterations.
33
33
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 in server-side JavaScript, we can kill the process.
34
+
If `i++`was missing from the example above, the loop would repeat (in theory) forever. In practice, the browser provides ways to stop such loops, and in server-side JavaScript, we can kill the process.
35
35
36
36
Any expression or variable can be a loop condition, not just comparisons: the condition is evaluated and converted to a boolean by `while`.
37
37
@@ -166,7 +166,7 @@ alert(i); // 3, visible, because declared outside of the loop
166
166
167
167
### Skipping parts
168
168
169
-
Any part of the `for` syntax can be skipped.
169
+
Any part of `for` can be skipped.
170
170
171
171
For example, we can omit `begin` if we don't need to do anything at the loop start.
172
172
@@ -190,9 +190,9 @@ for (; i < 3;) {
190
190
}
191
191
```
192
192
193
-
The loop became identical to `while (i < 3)`.
193
+
This makes the loop identical to `while (i < 3)`.
194
194
195
-
We can actually remove everything, thus creating an infinite loop:
195
+
We can actually remove everything, creating an infinite loop:
196
196
197
197
```js
198
198
for (;;) {
@@ -229,7 +229,7 @@ alert( 'Sum: ' + sum );
229
229
230
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 control to the first line after the loop. Namely, `alert`.
231
231
232
-
The combination "infinite loop + `break` as needed" is great for situations when a loop's condition must be checked not in the beginning or end of the loop, but in the middle or even in several places of the body.
232
+
The combination "infinite loop + `break` as needed" is great for situations when a loop's condition must be checked not in the beginning or end of the loop, but in the middle or even in several places of its body.
0 commit comments