Skip to content
Tutorials Center
My learning

Topics

JavaScript Reference ยท Statements and Declarations

The continue statement

Reference for the JavaScript continue statement: skipping the rest of a loop iteration, labeled continue for nested loops, and how it differs in each loop type.

The continue statement ends the current iteration of a loop and jumps to the next one. In a for loop it goes to the update expression and then the condition; in while and do...while it goes to the condition; in for...of and for...in it takes the next item. With a label it continues an outer loop.

It is useful for "guard clauses" in loops: skip uninteresting items at the top so the main work is not nested in an if.

JavaScript
for (const line of lines) {
  if (line.trim() === "") {
    continue;
  }
  process(line);
}

Try it

JS Skipping items

Press Run (or Ctrl + Enter) to see the console output here.

No output.

JS Labeled continue and the while trap

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Syntax

JavaScript
continue;
continue label;
Part Description
label Optional. The label of an enclosing loop to continue. Must be on the same line as continue.

Exceptions: a SyntaxError if continue is not inside a loop, or if the label does not name an enclosing loop.

Usage notes

  • Loops only. Unlike break, continue cannot be used in a switch alone or a plain block; it must be inside a loop (a switch inside a loop is fine and continues the loop).
  • What happens next depends on the loop: for runs the update expression first; while and do...while go straight to the condition; for...of and for...in fetch the next item.
  • while trap. If the variable that the condition checks is changed after the continue line, skipping it can create an infinite loop. Update first or use for.
  • Labeled continue resumes the labeled outer loop, running its next iteration, which replaces flag variables in nested loops.
  • Callbacks. continue does not work inside forEach callbacks; use return there to skip the current item.
  • Finally blocks run before control leaves a try via continue.
  • Style. continue at the top of a loop body flattens nesting. Too many continue/break statements in one loop can make flow hard to follow; consider filter().

Browser support

Supported in every JavaScript engine.