for-in
Ranges and iterating over collections.
Syntax
for i in 1...n { ... } // for x in arr { ... }Description
1...5 is a closed range (including 5), while 1..<5 excludes 5. for-in iterates through each element of an array in order.
Example
Loading editor…
Expected output
1 2 3 a b
When to use?
List processing, repetitive tasks.