Branching

Flow control structures enable developers to apply logical processes and make decisions about what code is executed. Most modern programming languages provide a similar set of flow control structures:

  • The if statements execute code blocks when a Boolean condition is true.
  • The while loops execute blocks of code while a Boolean condition remains true.
  • The for loops execute blocks of code a specific number of times.

It's said that virtually any programming control flow requirement can be implemented with a while statement alone. However, the other various control structures allow programmers to create control flow that's more concise and clearly expresses the intent of the logical program flow.

Indeed, Swift provides a rich and powerful set ...

Get Beginning Swift 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.