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.

for Loops

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 loop. for-in is often associated with a process known as fast enumeration—a simplified syntax that makes it easier to run specific code ...

Get Learning Swift™ Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.