continue
statement
JS Home <<
JS Reference <<
continue
Break from the current statement flow within a loop.
Description
Ends the current for
, while
and do....while
iteration loop and passes control to the next iteration as follows:
- When using the
continue
statement with afor
loop control passes to the expression. - When using the
continue
statement with awhile
ordo....while
loop control passes to thewhile
condition.
Syntax
Signature | Description |
---|---|
continue [label]; | Ends the current for , while , do....while iteration loop. |
Parameters
Parameter | Description |
---|---|
label | An optional identifier associated with a label statement. |
Examples
The code below shows an example of the continue
statement.
// execute the loop until break.
for (var i=0; i<4; i++) {
if (i == 2) {
continue;
}
alert('The i variable is = ' + i);
}
alert('left for loop');
The code below shows an example of the continue
and label
statements.
// execute the loop until loop condition is false.
for (var i=1; i<3; i++) {
atLabel:
for (var k=1; k<3; k++) {
if (k == 2) {
continue atLabel;
}
alert('The i variable is = ' + i + ' and k variable is = ' + k);
}
}
alert('left for loop');
Related Tutorials
JavaScript Intermediate Tutorials - Lesson 4 - While and Do....While Loops
JavaScript Intermediate Tutorials - Lesson 5 - For Loops