Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

The continue statement is a control flow mechanism used within iterative structures (for, while, do...while, for...in, for...of) to prematurely terminate the current iteration. When encountered, it bypasses all subsequent statements within the loop’s block for that specific iteration and immediately transfers control to the loop’s next iteration cycle.

Syntax

The statement can be used in two forms: unlabeled and labeled.
// Unlabeled
continue;

// Labeled
continue labelIdentifier;

Execution Mechanics

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

Unlabeled continue

When used without a label, the statement applies exclusively to the innermost enclosing loop.
for (let i = 0; i < 5; i++) {
    if (i === 2) {
        continue; // Control jumps to i++
    }
    console.log(i); // This statement is skipped when i === 2
}

Labeled continue

TypeScript supports labeled statements, which allow you to prefix a loop with an identifier. When continue is paired with a label, it bypasses the current iteration of the specific enclosing loop associated with that label, rather than defaulting to the innermost loop.
outerLoop: for (let i = 0; i < 3; i++) {
    for (let j = 0; j < 3; j++) {
        if (i === 1) {
            continue outerLoop; // Control jumps to i++ of the outer loop
        }
        console.log(`i: ${i}, j: ${j}`);
    }
}

Compiler Constraints

  • A continue statement must be nested within an iterative statement. Placing it outside of a loop results in a compile-time syntax error (TS1104: A 'continue' statement can only be used within an enclosing iteration statement).
  • When using the labeled form, the target label must exist on an enclosing iteration statement within the same function boundary. It cannot reference a label outside its lexical scope or a label attached to a non-loop block.
Master TypeScript with Deep Grasping Methodology!Learn More