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

# Kotlin Continue

The `continue` keyword in Kotlin is a structural jump expression that immediately terminates the execution of the current iteration within a loop (`for`, `while`, or `do-while`). Control flow is transferred directly to the loop's next iteration phase, bypassing any remaining statements in the current loop body.

Depending on the loop type, the exact control flow transfer behaves as follows:

* **`for` loop:** Control jumps to the retrieval of the next element from the underlying iterator.
* **`while` and `do-while` loops:** Control jumps directly to the evaluation of the loop's boolean condition.

In Kotlin's type system, `continue` evaluates to the `Nothing` type, signifying an expression that never completes normally.

## Unlabeled `continue`

By default, an unqualified `continue` statement applies to the innermost enclosing loop.

```kotlin theme={"dark"}
for (i in 1..5) {
    if (i % 2 == 0) {
        continue 
    }
    println(i)
}
```

## Labeled `continue`

Kotlin supports loop labeling, allowing developers to explicitly define the target loop for the jump expression. While frequently applied within nested loop architectures to bypass the innermost loop default, a labeled `continue` is syntactically valid on any labeled loop, including single, non-nested loops.

A label is defined using an identifier followed by the `@` symbol (e.g., `target@`). The `continue` expression invokes the label by appending the `@` symbol and the identifier (e.g., `continue@target`).

```kotlin theme={"dark"}
outerLoop@ for (i in 1..5) {
    for (j in 1..5) {
        if (j == 3) {
            continue@outerLoop 
        }
        println("i = $i, j = $j")
    }
}
```

## Lexical Scoping Constraints

The `continue` expression is strictly lexically scoped. It cannot be used to jump across function boundaries, including lambda expressions and anonymous objects. If a loop contains a higher-order function taking a lambda, a `continue` statement cannot be placed inside that lambda to affect the outer loop. Unlike the `return` keyword, which can perform non-local returns when used inside a lambda passed to an `inline` function, Kotlin does not support non-local `continue` (or `break`) statements under any circumstances.

However, within the valid lexical scope of the loop, `continue` can be deeply nested inside any block or expression. Because `continue` evaluates to `Nothing`, it satisfies any type requirement. This allows it to be used idiomatically on the right-hand side of the Elvis operator (`?:`), within `try-catch` blocks, or inside deeply nested conditional statements, provided no function or lambda boundaries are crossed.

```kotlin theme={"dark"}
for (item in listOf("A", null, "B")) {
    // Valid use of continue nested within an expression
    val nonNullItem = item ?: continue
    
    try {
        if (nonNullItem == "Skip") {
            continue
        }
        println(nonNullItem)
    } catch (e: Exception) {
        continue
    }
}
```

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