Logical Operators and Short-Circuiting
Combine conditions with &&, ||, ! and understand short-circuit evaluation.
Logical Operators
Logical operators combine Bool values: AND &&, OR ||, and NOT !. They are essential for building conditions.
let isWeekend = true
let isSunny = false
print(isWeekend && isSunny)
print(isWeekend || isSunny)
print(!isSunny)Logical NOT
The ! operator flips a boolean: true becomes false and vice versa.
let loggedIn = false
if !loggedIn {
print("Please log in")
}All lessons in this course
- Arithmetic and Compound Assignment Operators
- Comparison and Identity Operators
- Logical Operators and Short-Circuiting
- Bitwise and Overflow Operators