if and else
Conditions need no parentheses and braces are required.
Example
let n = 15
if n % 15 == 0 { print("FizzBuzz") }
else if n % 3 == 0 { print("Fizz") }
else { print(n) }
let kind = n % 2 == 0 ? "even" : "odd"
print(kind)Exercise
Else branch.
if x {} {}
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.