A conditional statement will check a condition and execute a block of code only if the condition is true. Swift provides both the if and if...else conditional statements. Let's take a look at how to use these conditional statements to execute blocks of code if a specified condition is true.
Conditional statements
The if statement
The if statement will check a conditional statement and, if it is true, it will execute the block of code. This statement takes the following format:
if condition { block of code }
Now, let's take a look at how to use the if statement:
let teamOneScore = 7 let teamTwoScore = 6 if teamOneScore > teamTwoScore { print("Team One Won") }
In the preceding example, we...