Break and Continue¶
The Break Statement¶
The break statement "jumps out" of a loop.
The Continue Statement¶
The continue statement breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop.
Labels¶
To jump out of a nested loop, you can use labels.
list: {
text += cars[0] + "<br>";
text += cars[1] + "<br>";
break list; // Jumps out of the list block
text += cars[2] + "<br>";
}
Labels
Labels are rarely used in modern JavaScript development, but it's good to know they exist.