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 an unconditional branching control flow construct that immediately terminates the execution of the current iteration within an enclosing loop. Upon execution, control is transferred directly to the loop’s next iteration phase, bypassing any remaining statements in the current loop body. The exact transfer of control depends on the type of the enclosing loop:
  • Traditional for loop: Control jumps to the loop’s update expression, followed by the evaluation of the boolean termination condition.
  • Enhanced for loop (for-each): Control transfers to the underlying iterator to check for and fetch the next element; there is no explicit update expression.
  • while and do-while loops: Control jumps directly to the evaluation of the boolean termination condition.
Java supports two forms of the continue statement: unlabeled and labeled.

Unlabeled continue

The unlabeled form affects only the innermost enclosing loop. It halts the current iteration of that specific loop and proceeds to its next iteration. Syntax:
continue;
Control Flow Visualization:
for (int i = 0; i < 10; i++) {
    // Statement A executed every iteration
    
    if (i % 2 == 0) {
        continue; // Halts current iteration, transfers control to i++
    }
    
    // Statement B executed ONLY if the condition evaluates to false
}

Labeled continue

The labeled form is used in conjunction with nested loops. It allows the developer to skip the current iteration of a specific outer loop, rather than the innermost loop. The label must immediately precede the target loop declaration. Syntax:
continue labelName;
Control Flow Visualization:
outerLoopLabel: 
for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
        
        if (i == j) {
            // Halts current iteration of BOTH loops.
            // Transfers control directly to i++ (the outer loop's update expression).
            continue outerLoopLabel; 
        }
        
        // Statement C
    }
    // Statement D
}

Technical Constraints

  • A continue statement must be strictly contained within the body of a for (traditional or enhanced), while, or do-while loop. Using it outside of a loop construct results in a compilation error.
  • A labeled continue must reference a valid label that is attached to an enclosing loop construct. Referencing a label attached to a non-loop block (like an if statement or a generic code block) will result in a compilation error.
Master Java with Deep Grasping Methodology!Learn More