JavaScript Statements Reference
In this example we use a for loop together with the continue statement.
Loop through a block of code, but skip the value of "3":
The result of text will be:
More "Try it Yourself" examples below.
The continue statement breaks one iteration (in the loop) if a specified condition occurs, and continues with the next iteration in the loop.
The difference between continue and the break statement, is instead of "jumping out" of a loop, the continue statement "jumps over" one iteration in the loop.
However, when the continue statement is executed, it behaves differently for different types of loops:
The continue statement can also be used with an optional label reference.
Note: The continue statement (with or without a label reference) can only be used inside a loop.
Statement | |||||
---|---|---|---|---|---|
continue | Yes | Yes | Yes | Yes | Yes |
Using the optional label reference:
JavaScript Version: | 1.0. The label reference was added in JavaScript 1.2 |
---|
In this example we use a while loop together with the continue statement.
Loop through a block of code, but skip the value of "3":
The result of text will be:
In this example we use a for loop together with the continue statement.
Loop through an array, but skip the array's element "Saab":
The result of text will be:
Using the continue statement with a label reference, to skip a value in a nested for loop:
The result of text will be:
JavaScript Tutorial: JavaScript Break and Continue
JavaScript Tutorial: JavaScript For Loop
JavaScript Tutorial: JavaScript While Loop
JavaScript Tutorial: JavaScript break Statement
JavaScript Reference: JavaScript for Statement
JavaScript Reference: JavaScript while Statement