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

# PHP Continue Statement

The `continue` statement is a control flow structure used within loop constructs (`for`, `foreach`, `while`, `do-while`) to immediately halt the execution of the current iteration. Upon encountering `continue`, the PHP engine skips any remaining statements in the current loop body and advances execution to the loop's next iteration boundary.

```php theme={"dark"}
continue;
// or
continue <level>;
```

## Execution Mechanics by Loop Type

The exact behavior of the iteration boundary depends on the enclosing loop structure:

* **`while` and `do-while` loops:** Execution jumps directly to the conditional expression to determine if the next iteration should proceed.
* **`for` loops:** Execution jumps to the loop's step expression (e.g., `$i++`), evaluates it, and then proceeds to the conditional expression.
* **`foreach` loops:** Execution advances the internal iteration state to the next element and evaluates if elements remain. (Note: Modern PHP uses an independent internal state for `foreach` iteration, not the array's internal pointer).

## Level Arguments

The `continue` statement accepts an optional argument (`<level>`) that dictates how many nested enclosing loop structures it should skip to the end of. This argument must be a **positive integer literal** (greater than `0`). The default value is `1`, which targets the immediate enclosing loop.

Passing `0` results in a Fatal Error. Passing negative numbers (e.g., `continue -1;`) results in a **Parse Error** (`syntax error, unexpected token "-"`) because the PHP grammar strictly expects a positive integer literal (`T_LNUMBER`) and cannot parse the minus sign in this context. As of PHP 8.0, passing variables as the level argument (e.g., `continue $var;`) results in a **Parse Error** (`syntax error, unexpected variable`).

```php theme={"dark"}
while ($conditionA) {
    while ($conditionB) {
        // Halts the current iteration of the inner loop, 
        // AND halts the current iteration of the outer loop,
        // jumping directly to the evaluation of $conditionA.
        continue 2; 
    }
}
```

## Behavior within `switch` Statements

In PHP, the `switch` statement is historically classified as a looping structure for the purposes of `continue`. Previously, executing `continue` (or `continue 1`) inside a `switch` behaved identically to `break`, terminating the `switch` block without affecting any outer loops.

However, as of PHP 8.0, using `continue` to target a `switch` statement results in a **Fatal Error** (Compile Error), meaning the script will fail to compile entirely. To terminate a `switch` block, `break` must be used.

```php theme={"dark"}
// Invalid usage (PHP 8.0+)
switch ($variable) {
    case 'A':
        // Throws a Fatal Error (Compile Error).
        // 'break;' must be used here to exit the switch block.
        continue;   
}
```

To skip an iteration of a loop that encloses a `switch` statement, a level argument of `2` or higher must be explicitly declared. This bypasses the `switch` and correctly targets the enclosing loop.

```php theme={"dark"}
// Valid usage targeting an outer loop
while ($condition) {
    switch ($variable) {
        case 'B':
            // Exits the switch AND skips the remainder of the while loop iteration.
            // This is valid and executes without error.
            continue 2; 
    }
}
```

<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 PHP 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>
