Book Image

Mastering Swift

By : Jon Hoffman
Book Image

Mastering Swift

By: Jon Hoffman

Overview of this book

Table of Contents (22 chapters)
Mastering Swift
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Control flow


Control flow, also known as flow of control, refers to the order in which statements, instructions, or functions are executed within an application. Swift supports all of the familiar control flow statements that are in C-like languages. These include loops (that is, for, while, and do/while), conditional statements (that is, if and switch) and the transfer of control statements (that is, break and continue). In addition to the standard C control flow statements, Swift has also added additional statements, such as the for-in loop, and has enhanced some of the existing statements, such as the switch statement.

Let's begin by looking at conditional statements in Swift.

Conditional statements

A conditional statement will check a condition and execute a block of code only if the condition is met. Swift provides both the if and if-else conditional statements. Let's take a look at how to use the if and if-else conditional statements to execute blocks of code, only if a specified condition...