Looping and Branching: Control Flow

Control flow refers to how we specify the order of how our Swift instructions are executed, or in a bigger picture, what parts of our code are to be run and under what conditions. In Swift, as in other languages, this is mostly implemented as conditionals and loops. Conditionals are statements that do or don’t execute code based on whether certain conditions are true or false at the time they’re evaluated. Loops build on conditionals by running some part of the code 0 or more times based on the conditions we provide.

Swift’s tools for control flow are probably very familiar to most developers, since many languages have if, for, while, and so forth. We’ll try them out now, so start a new playground called ...

Get iOS 9 SDK Development now with O’Reilly online learning.

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