July 2018
Beginner
202 pages
5h 42m
English
Closures can be used to create a custom iterator. In this section, you will build a custom iterator that will walk through an array, returning only the value stored in each index, not the index itself. The first time the iterator encounters a nil variable, it will terminate. This custom iterator will work with the generic for loop. A generic for loop holds on to three variables:
When a generic for executes, it evaluates the expressions after the in keyword. These expressions should result in the three values kept by the for: the iterator function, the invariant state, and the initial ...