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

# TypeScript Labeled Statement

A labeled statement provides a distinct identifier to a statement or block of code, enabling precise control flow manipulation when used in conjunction with `break` or `continue` directives. It allows execution to jump out of, or proceed to the next iteration of, a specific enclosing structure, bypassing the default behavior of targeting only the immediately enclosing loop or `switch`.

## Syntax

```typescript theme={"dark"}
labelIdentifier: statement
```

* **`labelIdentifier`**: Any valid JavaScript/TypeScript identifier that is not a reserved word.
* **`statement`**: The code block or loop being labeled.

## Control Flow Mechanics

Labeled statements alter the target of control flow directives:

1. **`break labelIdentifier;`**
   Terminates the execution of the labeled statement and transfers control to the statement immediately following it. While `break` typically only applies to loops and `switch` statements, a labeled `break` can be applied to *any* labeled block statement.

```typescript theme={"dark"}
outerBlock: {
    console.log("Entering block");
    if (true) {
        break outerBlock; // Exits 'outerBlock' immediately
    }
    console.log("Unreachable code");
}
```

2. **`continue labelIdentifier;`**
   Terminates the current iteration of the labeled loop and evaluates the loop's condition for the next iteration. Unlike `break`, a labeled `continue` can *only* be applied to iterative statements (`for`, `while`, `do...while`).

```typescript theme={"dark"}
outerLoop: for (let i = 0; i < 5; i++) {
    for (let j = 0; j < 5; j++) {
        if (j === 2) {
            continue outerLoop; // Skips remaining inner loop, advances 'i'
        }
    }
}
```

## Technical Constraints and Scope

* **Namespace Isolation**: Labels reside in a dedicated namespace. A label identifier can share the exact same name as a variable or function in the same scope without causing a naming collision.

```typescript theme={"dark"}
const foo = 10;
foo: for (let i = 0; i < foo; i++) { // Valid TS syntax
    break foo;
}
```

* **Lexical Boundaries**: The scope of a label is strictly limited to the statement it prefixes. Control flow cannot cross function boundaries; a `break` or `continue` cannot reference a label situated outside of its immediate enclosing function, including arrow functions or callbacks.

```typescript theme={"dark"}
loopLabel: for (let i = 0; i < 3; i++) {
    setTimeout(() => {
        // break loopLabel; // TS Error: Undefined label 'loopLabel'
    });
}
```

* **Duplicate Identifiers**: TypeScript throws a syntax error if overlapping (nested) statements share the same label identifier. However, identical labels are permitted if their scopes are entirely disjointed.
* **Strict Mode Restrictions**: Because TypeScript modules execute in strict mode by default, certain identifiers like `let`, `static`, `yield`, and `await` are strictly prohibited from being used as label names.

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