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

# Bash Break Statement

The `break` statement is a shell builtin command used to prematurely terminate the execution of an enclosing `for`, `while`, `until`, or `select` loop. When evaluated, it immediately halts the loop's execution cycle and transfers control flow to the command immediately following the terminated loop structure.

## Syntax

```bash theme={"dark"}
break [n]
```

## Parameters

* **`n` (Optional):** An integer literal (>= 1) specifying the number of nested loop levels to exit.
  * If omitted, `n` defaults to `1`, terminating only the innermost enclosing loop.
  * If `n` is greater than the current depth of nested loops, `break` terminates all enclosing loops and transfers control to the statement following the outermost loop.

## Execution Mechanics

1. **Scope:** `break` only applies to loop constructs. It does not terminate functions, scripts, or subshells (which require `return` or `exit`). While frequently nested inside conditional statements (`if` or `case`), `break` ignores these structures when calculating the depth `n` and only counts the enclosing loops.
2. **Exit Status:** The return status of the `break` command is `0` (success), unless the provided argument `n` is not an integer greater than or equal to `1`.
3. **Control Transfer:** Any commands remaining in the current loop iteration after the `break` statement are bypassed.

## Syntax Visualization

**Single Loop Termination (`break` or `break 1`)**

```bash theme={"dark"}
for i in 1 2 3; do
    echo "Starting iteration $i"
    
    if [ "$i" -eq 2 ]; then
        break
    fi
    
    echo "Finishing iteration $i" # Bypassed when i=2
done
echo "Control flow resumes here immediately after break"
```

**Nested Loop Termination (`break n`)**

```bash theme={"dark"}
for outer_var in 1 2; do
    for inner_var in A B; do
        echo "Outer: $outer_var, Inner: $inner_var"
        
        if [ "$outer_var" -eq 1 ] && [ "$inner_var" = "A" ]; then
            break 2  # Terminates both the inner and outer loops
        fi
        
        echo "Inner loop continuation" # Bypassed when break 2 is evaluated
    done
    echo "Outer loop continuation" # Bypassed when break 2 is evaluated
done
echo "Control flow resumes here immediately after break 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 Bash 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>
