Chapter    7

Flow Control

In programming, Control Flow refers to how the order of instructions (statements) are executed. Swift provides the standard set of conditional constructs. These include for, repeat, while, if, do, guard, and switch, plus break and continue to transfer the control to another location in the code.

Even though these constructs are familiar, they provide considerably powerful support for safety.

For Loops

A for loop construct provides a way for a block of code to be executed a number of times. Swift provides two types of for loops.

  • For-in is used in conjunction with objects that are contained in a range, sequence, collection, or progression. These typically include arrays and dictionaries.
  • For-conditional-increment performs ...

Get Learn Swift 2 on the Mac, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.