7.7 Using the if Statement
The if statement is perhaps the most basic of control flow options available to the Swift programmer. Programmers who are familiar with C, Objective-C, C++ or Java will immediately be comfortable using Swift if statements.
The basic syntax of the Swift if statement is as follows:
if boolean expression {
// Swift code to be performed when expression evaluates to true
}
Unlike some other programming languages, it is important to note that the braces ({}) are mandatory in Swift, even if only one line of code is executed after the if expression.
Essentially if the Boolean expression evaluates to true then the code in the body of the statement is executed. The body of the statement is enclosed in braces ({}). If, on the other hand, the expression evaluates to false the code in the body of the statement is skipped.
For example, if a decision needs to be made depending on whether one value is greater than another...