> ## 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 Labeled Break

A labeled break in Kotlin is a control flow construct that allows execution to jump out of a specific enclosing loop within a nested loop hierarchy. While a standard `break` expression implicitly terminates the nearest enclosing loop, a labeled break explicitly directs the compiler to terminate a targeted loop, transferring execution to the statement immediately following that labeled loop.

## Syntax

A label is defined by an identifier followed immediately by the `@` symbol, placed directly before the loop declaration. The break expression is invoked using the `break` keyword followed by `@` and the identifier, with no whitespace.

```kotlin theme={"dark"}
labelName@ for (item in collection) {
    while (condition) {
        break@labelName
    }
}
```

## Mechanics and Resolution

* **Label Declaration:** Any valid Kotlin identifier can be used as a label (e.g., `outer@`, `loopA@`). The label is bound to the loop construct it precedes.
* **Invocation:** When `break@labelName` is evaluated, it performs a local jump (compiled to a `goto` instruction in JVM bytecode) to exit the nested blocks. Because standard loops are local control flow structures, this operation does not involve unwinding the call stack.
* **Lexical Scoping:** The label must reference an enclosing loop within the current lexical scope. A labeled break cannot target a loop in a separate function, a sibling loop, or an inner loop.
* **Execution Flow:** Upon invocation, the targeted loop is immediately terminated. Any remaining iterations of both the inner loops and the targeted outer loop are discarded. Execution resumes at the first expression following the closing brace of the targeted loop.

## Structural Example

The following demonstrates the execution flow when a labeled break is triggered:

```kotlin theme={"dark"}
outer@ for (i in 1..3) {
    for (j in 1..3) {
        if (i == 2 && j == 2) {
            // Terminates the loop labeled 'outer@'
            // A standard 'break' would only terminate the 'j' loop
            break@outer 
        }
        println("i=$i, j=$j")
    }
}
// Execution jumps directly here when break@outer is evaluated
println("Loop terminated")
```

**Execution Output:**

```text theme={"dark"}
i=1, j=1
i=1, j=2
i=1, j=3
i=2, j=1
Loop terminated
```

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