JavaScript Break and Continue

The break explanation "jumps out" of a loop.

The proceed with explanation "jumps over" one emphasis in the loop.

The Break Statement

You have just observed the break articulation utilized in a before section of this instructional exercise. It was utilized to "jump out" of a switch() statement.

The break explanation can likewise be utilized to bounce out of a loop.  

The break statement breaks the circle and keeps executing the code after the circle (if any):


for (I = 0; I < 10; i++) {
    on the off chance that (I === 3) { break; }
    content += "The number is " + I + "<br>";
Try it yourself »

The Continue Statement

The continue statement breaks one emphasis (on top of it), if a predefined condition happens, and proceeds with the following emphasis in the loop.

This precedent skirts the estimation of 3:


for (I = 0; I < 10; i++) {
    on the off chance that (I === 3) { proceed; }
    content += "The number is " + I + "<br>";
Try it yourself »

JavaScript Labels

To mark JavaScript proclamations you go before the announcements with a name what's more, a colon:


The break and the proceed with proclamations are the main JavaScript explanations that can "jump out of" a code block.


break labelname;

continue labelname;

The proceed explanation (with or without a name reference) must be utilized to skip one circle iteration.

The break explanation, without a name reference, must be utilized to hop out of a circle or then again a switch.

With a mark reference, the break articulation can be utilized to jump out of any code block:


var autos = ["BMW", "Volvo", "Saab", "Ford"];
list: {
    content += cars[0] + "<br>";
    content += cars[1] + "<br>";
    content += cars[2] + "<br>";
    content += cars[3] + "<br>";
    break list;
    content += cars[4] + "<br>";
    content += cars[5] + "<br>";
Try it Yourself »