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
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!"