Skip to main content

Continue and break Statement

break Statement

The break statement is used to exit from loop early.

Example

var x = 1;
while (x <= 10) {
console.log(x);
x++;
if (x == 6) break;
}

In this example break is used inside the if statement. When value of x become 6 loop breaks.

continue Statement

The continue statement is used to immediately start next iteration by skipping current iteration of the loop.

Example

for (var i = 1; i <= 10; i++) {
if (i === 6) {
continue;
}
console.log(i);
}

The expected output of this example is values from 1 to 10 is printed, except 6 because we set continue statement at i == 6.