Merge pull request #3028 from Rnbsov/patch-57

👾 smth
This commit is contained in:
Ilya Kantor 2022-06-13 12:15:56 +02:00 committed by GitHub
commit 05a2b8d80d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -162,10 +162,8 @@ for (i = 0; i < 3; i++) { // use an existing variable
alert(i); // 3, visible, because declared outside of the loop
```
````
### Skipping parts
Any part of `for` can be skipped.
@ -286,7 +284,6 @@ if (i > 5) {
...and rewrite it using a question mark:
```js no-beautify
(i > 5) ? alert(i) : *!*continue*/!*; // continue isn't allowed here
```
@ -321,6 +318,7 @@ We need a way to stop the process if the user cancels the input.
The ordinary `break` after `input` would only break the inner loop. That's not sufficient -- labels, come to the rescue!
A *label* is an identifier with a colon before a loop:
```js
labelName: for (...) {
...
@ -342,6 +340,7 @@ The `break <labelName>` statement in the loop below breaks out to the label:
// do something with the value...
}
}
alert('Done!');
```
@ -362,6 +361,7 @@ The `continue` directive can also be used with a label. In this case, code execu
Labels do not allow us to jump into an arbitrary place in the code.
For example, it is impossible to do this:
```js
break label; // jump to the label below (doesn't work)
@ -369,6 +369,7 @@ label: for (...)
```
A `break` directive must be inside a code block. Technically, any labelled code block will do, e.g.:
```js
label: {
// ...