TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
continue keyword is a control flow expression used within loop constructs (loop, while, while let, and for) to immediately terminate the execution of the current iteration. When evaluated, it bypasses all subsequent statements in the current loop body and forces the control flow to jump directly to the next iteration’s evaluation phase.
In Rust’s expression-oriented design, continue evaluates to the never type (!). Because the never type represents a computation that never resolves to a value, it can be safely coerced into any other type. This allows continue to be used in contexts that expect a specific type, such as within if or match expressions that are bound to a variable.
Basic Syntax and Type Coercion
Execution Mechanics by Loop Type
The exact behavior of the jump triggered bycontinue depends on the loop construct enclosing it:
forloops: Control flow jumps to the iterator’snext()method. If a new value is yielded, it is bound to the loop pattern, and the loop body executes again.whileloops: Control flow jumps back to the loop’s boolean condition. The condition is re-evaluated; iftrue, the loop body executes again.while letloops: Control flow jumps back to the pattern matching evaluation. If the expression successfully matches the pattern again, the loop body executes.loopconstructs: Because there is no condition or iterator to evaluate, control flow jumps directly to the first statement at the top of the loop block.
Labeled continue
By default, continue applies only to the innermost enclosing loop. To alter the control flow of nested loops, Rust utilizes loop labels. A label is defined with a single quote followed by an identifier ('label_name:).
When continue is paired with a label, it terminates the current iteration of the specified outer loop, bypassing the remaining execution of both the inner and outer loop bodies for that iteration.
Scope and Constraints
- Context Restriction:
continueis strictly bound to loop execution contexts. Attempting to use it outside of aloop,while,while let, orforblock results in a compile-time error (E0268). - Value Yielding: Unlike the
breakstatement, which can return a value from aloopconstruct (e.g.,break counter;),continuecannot carry or return a value. Its sole function is control flow redirection.
Master Rust with Deep Grasping Methodology!Learn More





