Calls the given closure on each element in the sequence in the same order as a
- iOS 7.0+
- macOS 10.9+
- UIKit for Mac 13.0+Beta
- tvOS 9.0+
- watchOS 2.0+
- Xcode 8.0+
A closure that takes an element of the sequence as a parameter.
The two loops in the following example produce the same output:
for method is distinct from a
in loop in two important ways:
You cannot use a
continuestatement to exit the current call of the
bodyclosure or skip subsequent calls.
returnstatement in the
bodyclosure will exit only from the current call to
body, not from any outer scope, and won’t skip subsequent calls.