April 2026
Intermediate
683 pages
25h 29m
English
The good news first: You already know the basics about loops! In Chapter 3, you learned about iterations over collections when we ran a code snippet for each element in a collection (like an array) sequentially. That is the very core logic of loops. In this section, we will build up further knowledge on top of that and see how loops function as a generic control flow mechanism.
We’ll start with for … in … loops, which should already be familiar. As a memory refresher, Listing 4.23 features a simple iteration over an array, which prints out each element sequentially.
let fruits = ["apple", "banana", "orange"]for fruit in fruits { print(fruit) // apple, banana, orange}
Listing 4.23 Iteration over Array
Read now
Unlock full access