To label JavaScript statements, you place a label name followed by a colon before the statements.
label: statements |
The break and continue statements are the only JavaScript commands that can “exit” a code block.
Syntax:
break labelname; continue labelname; |
The continue statement (with or without a label) is designed to skip a single iteration of a loop.
The break statement, when used without a label, can only exit a loop or a switch statement.
However, with a label reference, the break statement can be used to exit any code block.
const cars = [“BMW”, “Volvo”, “Saab”, “Ford”]; list: { text += cars[0] + “<br>”; text += cars[1] + “<br>”; break list; text += cars[2] + “<br>”; text += cars[3] + “<br>”; } |