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 a for loop control passes to the expression.
  • When using the continue statement with a while or do....while loop control passes to the while condition.

Syntax

Signature Description
continue [label];Ends the current for, while, do....while iteration loop.

Parameters

Parameter Description
labelAn 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');

Press the button below to action the above code:

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');

Press the button below to action the above code:

Related Tutorials

JavaScript Intermediate Tutorials - Lesson 4 - While and Do....While Loops
JavaScript Intermediate Tutorials - Lesson 5 - For Loops