<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Array/forEach(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:STsE7forEachyyy7ElementQzKXEKF::SYNTHESIZED::s:Sa"
  },
  "title" : "forEach(_:)"
}
-->

# forEach(_:)

Calls the given closure on each element in the sequence in the same order
as a `for`-`in` loop.

```
func forEach(_ body: (Self.Element) throws -> Void) rethrows
```

## Parameters

`body`

A closure that takes an element of the sequence as a
parameter.

## Discussion

The two loops in the following example produce the same output:

```
let numberWords = ["one", "two", "three"]
for word in numberWords {
    print(word)
}
// Prints "one"
// Prints "two"
// Prints "three"

numberWords.forEach { word in
    print(word)
}
// Same as above
```

Using the `forEach` method is distinct from a `for`-`in` loop in two
important ways:

1. You cannot use a `break` or `continue` statement to exit the current
   call of the `body` closure or skip subsequent calls.
2. Using the `return` statement in the `body` closure will exit only from
   the current call to `body`, not from any outer scope, and won’t skip
   subsequent calls.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)