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 construct that alters the standard sequential execution of a program. Depending on its context and syntax, it either terminates the current iteration of an enclosing loop to immediately begin the next iteration, or transfers execution to a specific labeled case clause within a switch statement.

Syntax

// Unlabeled
continue;

// Labeled
continue labelName;

Scope and Constraints

The validity and behavior of the continue statement depend strictly on whether a label is applied, and are bound by strict lexical constraints:
  • Unlabeled continue: Strictly confined to the lexical scope of loop constructs (for, for-in, await for, while, do-while). Using an unlabeled continue outside of a loop results in a compile-time error.
  • Labeled continue: Can be used within nested loops to target a specific enclosing loop, or within a switch statement to jump directly to a labeled case clause. It cannot be used as a general-purpose goto to reach arbitrary labels outside of these specific control flow structures.
  • Function Boundaries: A continue statement cannot cross function boundaries. It is invalid to use continue inside a closure or local function (such as a callback passed to an Iterable.forEach() method) to skip an iteration of an enclosing loop.

Execution Mechanics

Unlabeled Continue (Loops)

When an unlabeled continue is encountered, the Dart runtime bypasses any remaining statements within the innermost loop’s body for that specific cycle. The exact transfer of control depends on the loop type:
  • for loops: Control transfers directly to the update expression (e.g., i++), followed by the evaluation of the loop condition.
  • while and do-while loops: Control transfers directly to the boolean condition expression.
  • for-in and await for loops: Control transfers to the retrieval of the next element from the underlying Iterable or Stream.
for (int i = 0; i < 4; i++) {
  if (i == 2) {
    continue; // Bypasses the print statement when i equals 2
  }
  print(i); 
}
// Output: 0, 1, 3

Labeled Continue (Loops)

Dart utilizes labels (identifiers followed by a colon) to target specific loops in a nested structure. When continue is invoked with a loop label, it bypasses the remaining body of the current loop and jumps to the next iteration (update expression or condition evaluation) of the explicitly labeled outer loop.
outerLoop: // Label definition
for (int i = 0; i < 3; i++) {
  for (int j = 0; j < 3; j++) {
    if (i == 1 && j == 1) {
      // Terminates the inner loop and jumps to the 
      // update expression (i++) of outerLoop
      continue outerLoop; 
    }
    print('i: $i, j: $j');
  }
}

Labeled Continue (Switch Statements)

Within a switch statement, a labeled continue acts as a directed jump. It transfers execution directly to another case clause that has been marked with the corresponding label, allowing execution to proceed from that specific case. Modern Dart (3.0+) utilizes implicit break semantics, meaning explicit break statements are not required to prevent fallthrough.
int statusCode = 200;

switch (statusCode) {
  case 200:
    print('OK');
    continue redirectLabel; // Jumps directly to redirectLabel
  case 404:
    print('Not Found');
  redirectLabel: // Label attached to a specific case
  case 301:
    print('Redirecting');
}
Master Dart with Deep Grasping Methodology!Learn More