JavaScript continue Statement
JavaScript Statements Reference Manual
Examples
The examples we use continue statement in a loop.
Loop code block, the value of i is equal to skip the current cycle "3":
var i;
for (i = 0; i <5; i ++) {
if (i == 3) {
continue;
}
text + = "The number is" + i + "<br>";
}
text output is:
The number is 1
The number is 2
The number is 4
try it"
Bottom of this article contains more examples.
Definition and Usage
continue for skipping a loop iteration and continue with the next iteration of the loop.
continue and break difference statement is, break the end of the whole body of the loop, continue to end single cycle.
However, in the implementation of continue statement, showing two different types of loops:
- In the while loop, the condition will first determine if the condition is true, execute the cycle once again.
- In the for loop, since growth expression (such as: i ++) will be calculated, and then determine whether a condition is true, then decide whether to perform the iteration.
continue statement can be used in an optional label references.
Note: continue statement (with no label references), it can only be used in loops or switch.
Browser Support
Statements | |||||
---|---|---|---|---|---|
continue | Yes | Yes | Yes | Yes | Yes |
grammar
Using the optional label references:
technical details
JavaScript version: | 1.0. JavaScript 1.2 supports an optional label references. |
---|
More examples
Examples
The examples we use continue statement in while loop.
Loop code block, the i is equal to skip the current cycle "3":
var i = 0;
while (i <5) {
i ++;
if (i == 3) {
continue;
}
text + = "<br> The number is" + i;
}
text output is:
The number is 2
The number is 4
The number is 5
try it"
Examples
The examples we use continue statement in a for loop.
Loop through the array, in the elements of the array to "Saab" skip the current cycle:
var text = ""
var i;
for (i = 0; i <cars.length; i ++) {
if (cars [i] == "Saab") {
continue;
}
text + = cars [i] + "<br>";
}
text output is:
Volvo
Ford
try it"
Examples
Continue to use the statement in the label references for out of a block of code:
var i, j;
Loop1: // first loop label "Loop1"
for (i = 0; i <3; i ++) {
text + = "<br>" + "i =" + i + ", j =";
Loop2: // The second loop tag "Loop2"
for (j = 10; j <15; j ++) {
if (j == 12) {
continue Loop2;
}
. Document.getElementById ( "demo") innerHTML = text + = j + "";
}
}
text output is:
i = 1, j = 10 11 13 14
i = 2, j = 10 11 13 14
try it"
Related Pages
JavaScript Tutorials: JavaScript Break and Continue
JavaScript Tutorials: JavaScript cycle
JavaScript Tutorials: JavaScript the While loop
JavaScript Tutorials: JavaScript BREAK statement
JavaScript Reference Manual: JavaScript for statements
JavaScript Reference Manual: JavaScript the while statement
JavaScript Statements Reference Manual