File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed
1-js/02-first-steps/13-while-for Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -162,10 +162,8 @@ for (i = 0; i < 3; i++) { // use an existing variable
162162
163163alert(i); // 3, visible, because declared outside of the loop
164164```
165-
166165````
167166
168-
169167### Skipping parts
170168
171169Any part of ` for ` can be skipped.
@@ -286,7 +284,6 @@ if (i > 5) {
286284
287285...and rewrite it using a question mark:
288286
289-
290287```js no-beautify
291288(i > 5) ? alert(i) : *!*continue*/!*; // continue isn't allowed here
292289```
@@ -321,6 +318,7 @@ We need a way to stop the process if the user cancels the input.
321318The ordinary ` break ` after ` input ` would only break the inner loop. That's not sufficient -- labels, come to the rescue!
322319
323320A * label* is an identifier with a colon before a loop:
321+
324322``` js
325323labelName: for (... ) {
326324 ...
@@ -342,6 +340,7 @@ The `break <labelName>` statement in the loop below breaks out to the label:
342340 // do something with the value...
343341 }
344342}
343+
345344alert (' Done!' );
346345```
347346
@@ -362,13 +361,15 @@ The `continue` directive can also be used with a label. In this case, code execu
362361Labels do not allow us to jump into an arbitrary place in the code.
363362
364363For example, it is impossible to do this:
364+
365365```js
366366break label; // jump to the label below (doesn't work)
367367
368368label: for (...)
369369```
370370
371371A `break` directive must be inside a code block. Technically, any labelled code block will do, e.g.:
372+
372373```js
373374label: {
374375 // ...
You can’t perform that action at this time.
0 commit comments