0Pricing
Swift Academy · Lesson

Iterating Collections with for-in

Looping over arrays, dictionaries and sets with enumerated and zip.

Welcome

The `for-in` loop works with any `Sequence` — arrays, dictionaries, sets, strings, and your own custom types. Let's see the most useful patterns.

Iterating an Array

```swift let fruits = ["apple", "banana", "cherry"] for fruit in fruits { print(fruit) } // apple, banana, cherry ``` Each element is bound to `fruit` for one iteration.

All lessons in this course

  1. for-in Loops with Ranges
  2. while and repeat-while Loops
  3. Iterating Collections with for-in
  4. break, continue and Labeled Statements
← Back to Swift Academy