We can use the forEach algorithm to iterate over a sequence. The following example shows how we would do this:
var arrayOne = [10, 20, 30, 40] arrayOne.forEach{ print($0) }
This example will print the following results to the console:
10 20 30 40
While using the forEach algorithm is very easy, it does have some limitations. The recommended way to iterate over an array is to use the for-in loop, which we will see in the next section.