Control Flow: Making Choices
Controlling the order in which code executes is a crucial aspect of any programming language. By building on the traditions of C and C-like languages, Swift’s control flow constructs allow for powerful functionality while still maintaining a familiar syntax.
At its most basic, a
for loop allows you to execute code repeatedly. You can also say that code statements are “looping” a certain number of times (or infinitely). In the Swift language, there are two distinct types of
for loops to consider. There is the traditional
for-condition-increment loop, and there is the
for-in is often associated with a process known as fast enumeration—a simplified syntax that makes it easier to run specific code ...