Logical operators let you combine or flip Boolean values. They're the building blocks of decision-making in your code.
&& — AND
Both sides must be true for the result to be true.
fun main() {
val age = 25
val hasLicense = true
println(age >= 18 && hasLicense) // true - both conditions are met
println(age >= 30 && hasLicense) // false - age condition fails
}
|| — OR
At least one side must be true. Great for "either this or that" situations.
fun main() {
val isWeekend = false
val isHoliday = true
println(isWeekend || isHoliday) // true - holiday is true
println(isWeekend || false) // false - neither is true
}
! — NOT
Flips true to false and false to true. Simple but powerful.
fun main() {
val isRaining = false
println(!isRaining) // true
println(!true) // false
}
Try it Yourself →