Bool is a Boolean type with two possible values: true
and false
.
let aTrueBool = true
let aFalseBool = false
Bools are used in control-flow statements as conditions. The [if
](http://stackoverflow.com/documentation/swift/475/conditionals/1559/basic-conditionals-if-statements#t=201607182137080572886) statement uses a Boolean condition to determine which block of code to run:
func test(_ someBoolean: Bool) {
if someBoolean {
print("IT'S TRUE!")
}
else {
print("IT'S FALSE!")
}
}
test(aTrueBool) // prints "IT'S TRUE!"