> ## 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.

# Rust Continue

The `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

```rust theme={"dark"}
fn main() {
    for x in 0..5 {
        // `continue` evaluates to `!`, which coerces to `i32` to match the `else` block
        let value: i32 = if x % 2 == 0 {
            continue; 
        } else {
            x * 10
        };
        
        println!("{}", value);
    }
}
```

## Execution Mechanics by Loop Type

The exact behavior of the jump triggered by `continue` depends on the loop construct enclosing it:

* **`for` loops:** Control flow jumps to the iterator's `next()` method. If a new value is yielded, it is bound to the loop pattern, and the loop body executes again.
* **`while` loops:** Control flow jumps back to the loop's boolean condition. The condition is re-evaluated; if `true`, the loop body executes again.
* **`while let` loops:** Control flow jumps back to the pattern matching evaluation. If the expression successfully matches the pattern again, the loop body executes.
* **`loop` constructs:** 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.

```rust theme={"dark"}
fn main() {
    'outer: for x in 1..=3 {
        for y in 1..=3 {
            if x == y {
                // Terminates the current iteration of the 'outer loop.
                // The inner loop is aborted, and 'outer advances to the next `x`.
                continue 'outer; 
            }
            println!("x: {}, y: {}", x, y);
        }
    }
}
```

## Scope and Constraints

* **Context Restriction:** `continue` is strictly bound to loop execution contexts. Attempting to use it outside of a `loop`, `while`, `while let`, or `for` block results in a compile-time error (`E0268`).
* **Value Yielding:** Unlike the `break` statement, which can return a value from a `loop` construct (e.g., `break counter;`), `continue` cannot carry or return a value. Its sole function is control flow redirection.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Rust Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
