> 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/return.md).

# return

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

{% tabs %}
{% tab title="🧨 雷區" %}
{% hint style="danger" %} <mark style="color:red;">**cannot**</mark> use <mark style="color:purple;">**return**</mark> in the body of a [for...in](/ios/swift/flow/loop/for...in.md) loop, <mark style="color:yellow;">**except**</mark> that the loop is <mark style="color:yellow;">**inside**</mark> a <mark style="color:yellow;">**function**</mark>.
{% endhint %}

* [replit](https://replit.com/@pegasusroe/forin-vs-forEach#main.swift) ( 👉 see: [for...in vs. forEach](/ios/swift/flow/loop/for...in-vs.-foreach.md) )

{% hint style="danger" %}
⛔ <mark style="color:red;">**error**</mark>: [return](/ios/swift/flow/transfer/return.md) <mark style="color:red;">**invalid**</mark>**&#x20;**<mark style="color:yellow;">**outside**</mark> of a <mark style="color:blue;">**func**</mark>.
{% endhint %}

```javascript
for n in 1...10 {
    if n == 3 { return }    // ⛔ error
    //          ^^^^^^
    // ⛔ error: return invalid outside of a func
}
```

{% endtab %}

{% tab title="👥 相關" %}

* [return value](/ios/swift/type/category/basic/func/return.md)
* [implicit return](/ios/swift/type/implicit-return.md)
  {% endtab %}

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

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