Basics: Booleans

Let orangesAreOrange = true
let turnipsAreDelicious = false
If turnipsAreDelicious {
    print("Mmm, tasty turnips!")
} else {
    print("Eww, turnips are horrible.")
}
// Prints "Eww, turnips are horrible."
Let i = 1
if i {
    // this example will not compile, and will report an error
}
Let i = 1
if i == 1 {
    // this example will compile successfully
}

Swift has a basic Boolean type, called Bool.

Additional information

  • Values are referred to as logical, because they can only ever be true or false.
  • Are particularly useful when you work with conditional statements.

Related concepts

Basics: Booleans — Structure map

Clickable & Draggable!

Basics: Booleans — Related pages: