Fix: Corrected terminologies for break and continue. They shouldn't be called directive by Shivamaggw · Pull Request #3985 · javascript-tutorial/en.javascript.info · GitHub
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -219,7 +219,7 @@ Please note that the two `for` semicolons `;` must be present. Otherwise, there
Normally, a loop exits when its condition becomes falsy.
But we can force the exit at any time using the special `break` directive.
But we can force the exit at any time using the special `break` statement.
For example, the loop below asks the user for a series of numbers, "breaking" when no number is entered:
Expand All
@@ -240,13 +240,13 @@ while (true) {
alert( 'Sum: ' + sum );
```
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`.
The `break` statement 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`.
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.
## Continue to the next iteration [#continue]
The `continue` directive is a "lighter version" of `break`. It doesn't stop the whole loop. Instead, it stops the current iteration and forces the loop to start a new one (if the condition allows).
The `continue` statement is a "lighter version" of `break`. It doesn't stop the whole loop. Instead, it stops the current iteration and forces the loop to start a new one (if the condition allows).
We can use it if we're done with the current iteration and would like to move on to the next one.
Expand All
@@ -262,9 +262,9 @@ for (let i = 0; i < 10; i++) {
}
```
For even values of `i`, the `continue` directive stops executing the body and passes control to the next iteration of `for` (with the next number). So the `alert` is only called for odd values.
For even values of `i`, the `continue` statement stops executing the body and passes control to the next iteration of `for` (with the next number). So the `alert` is only called for odd values.
A loop that shows odd values could look like this:
```js run
Expand All
@@ -283,7 +283,7 @@ But as a side effect, this created one more level of nesting (the `alert` call i
````
````warn header="No `break/continue` to the right side of '?'"
Please note that syntax constructs that are not expressions cannot be used with the ternary operator `?`. In particular, directives such as `break/continue` aren't allowed there.
Please note that syntax constructs that are not expressions cannot be used with the ternary operator `?`. In particular, statements such as `break/continue` aren't allowed there.
For example, if we take this code:
Expand Down
Expand Up
@@ -368,7 +368,7 @@ outer:
for (let i = 0; i < 3; i++) { ... }
```
The `continue` directive can also be used with a label. In this case, code execution jumps to the next iteration of the labeled loop.
The `continue` statement can also be used with a label. In this case, code execution jumps to the next iteration of the labeled loop.
````warn header="Labels do not allow to \"jump\" anywhere"
Labels do not allow us to jump into an arbitrary place in the code.
Expand All
@@ -381,7 +381,7 @@ break label; // jump to the label below (doesn't work)
label: for (...)
```
A `break` directive must be inside a code block. Technically, any labelled code block will do, e.g.:
A `break` statement must be inside a code block. Technically, any labelled code block will do, e.g.:
```js
label: {
Expand All
@@ -404,8 +404,8 @@ We covered 3 types of loops:
- `do..while` -- The condition is checked after each iteration.
- `for (;;)` -- The condition is checked before each iteration, additional settings available.
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.
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` statement.
If we don't want to do anything in the current iteration and would like to forward to the next one, we can use the `continue` directive.
If we don't want to do anything in the current iteration and would like to forward to the next one, we can use the `continue` statement.
`break/continue` support labels before the loop. A label is the only way for `break/continue` to escape a nested loop to go to an outer one.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: Corrected terminologies for break and continue. They shouldn't be called directive #3985
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Fix: Corrected terminologies for break and continue. They shouldn't be called directive #3985
Filter by extension
Viewed files
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing