Skip to main content
The continue statement is a control flow mechanism used within loop structures to prematurely terminate the execution of the current iteration. When the JavaScript engine encounters a continue statement, it bypasses all subsequent statements remaining in the loop’s body for that specific iteration and immediately transfers control to the loop’s next iteration cycle.

Syntax

Execution Mechanics

The exact behavior of the control flow transfer depends on the type of loop enclosing the continue statement:
  • for loop: Control jumps directly to the loop’s update expression (e.g., i++). After the update expression executes, the loop’s condition is evaluated to determine if the next iteration should proceed.
  • while and do...while loops: Control jumps directly to the loop’s condition evaluation.
  • for...in and for...of loops: Control advances to the next enumerable property or iterable value in the sequence.

Unlabeled continue

When used without a label, continue applies strictly to the innermost enclosing loop.

Labeled continue

JavaScript allows statements to be prefixed with a label identifier. When continue is paired with a label, it bypasses the current iteration of the specific loop associated with that label, rather than defaulting to the innermost loop. This is primarily utilized in nested loop architectures.

Technical Constraints

  1. Scope Restriction and Function Boundaries: A continue statement must be nested within an iterative statement (while, do...while, for, for...in, or for...of). Crucially, continue cannot cross function boundaries. Using continue inside a nested function—such as a callback passed to .forEach(), .map(), or setTimeout()—will throw a SyntaxError, even if that function is physically defined or executed inside a loop.
  1. Automatic Semicolon Insertion (ASI): The continue statement is subject to JavaScript’s ASI rules. No line terminator (line break) is permitted between the continue keyword and its target labelIdentifier. If a line break exists, the engine will automatically insert a semicolon after continue. This does not throw a SyntaxError, but it creates a logical error by executing an unlabeled continue and rendering the subsequent label an unreachable expression statement.
Tired of Poor JavaScript Skills? Fix That With Deep Grasping!Learn More