控制流 / 条件语句 / if/else 语句

func getLatitude() -> Int {
    return (-90...90).randomElement()!
}

let l = getLatitude()
var location = ""
if l == 0 {
    location = "Equator"
else if l == 90 {
    location = "north Pole"
else if l == -90 {
    location = "south Pole"
else {
    location = "not at the Equator or Pole"
}
print("latitude \(l): \(location)")


In its simplest form, the if statement has a single if condition. It executes a set of statements only if that condition is true.
The if statement can provide an alternative set of statements, known as an else clause, for situations when the if condition is false. These statements are indicated by the else keyword.