> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/ios/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/ios/swift/flow/transfer/break.md).

# break

🚧 施工中

[Swift](/ios/swift.md) ⟩ [flow control](/ios/swift/flow.md) ⟩ [control transfer](/ios/swift/flow/transfer.md) ⟩ break

{% tabs %}
{% tab title="🧨 雷區" %}
{% hint style="danger" %}
⛔ <mark style="color:red;">**error**</mark>: \ <mark style="color:yellow;">**unlabeled '**</mark><mark style="color:purple;">**break**</mark><mark style="color:yellow;">**'**</mark> is <mark style="color:yellow;">**only allowed**</mark>**&#x20;**<mark style="color:orange;">**inside**</mark> a [loop](/ios/swift/flow/loop.md) or [switch](/ios/swift/flow/branch/switch.md), a <mark style="color:yellow;">**labeled**</mark>**&#x20;**<mark style="color:purple;">**break**</mark> is <mark style="color:orange;">**required**</mark> to exit an [if](/ios/swift/flow/branch/if.md) or do. ( 👉 see: [for...in vs. forEach](/ios/swift/flow/loop/for...in-vs.-foreach.md) )
{% endhint %}

* replit：[for...in vs. forEach](https://replit.com/@pegasusroe/forin-vs-forEach#main.swift)

```javascript
(1...10).forEach { n in 
    
    if n > 2 { break }    // ⭐ `break` is inside a "closure"
    //         ^^^^^
    // ⛔ error: 
    //  • unlabeled 'break' is only allowed inside a loop or switch
    //  • labeled 'break' is required to exit an `if` or `do`
}
```

{% endtab %}

{% tab title="📘 手冊" %}

* [ ] [Control Transfer Statements](https://docs.swift.org/swift-book/LanguageGuide/ControlFlow.html#ID135)
  {% endtab %}

{% tab title="🚧 " %}

* labeled 'break'
* unlabeled 'break'
  {% endtab %}
  {% endtabs %}
