Skip to main content
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

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.

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.

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.
Tired of Poor Dart Skills? Fix That With Deep Grasping!Learn More