Kotlin Logical Operators
Logical operators are used to perform logic gate operations in programming language.
In this tutorial, you shall learn about different logical operators available in Kotlin programming language, the symbol used for each logical operator, and examples to see how to use these logical operators in Kotlin programs.
Logical Operators Table
The following table covers Logical Operators in Kotlin.
Operator | Symbol | Example | Description |
---|---|---|---|
AND | && | x&&y | Returns true if both x and y are true, else returns false. |
OR | || | x||y | Returns true if at least one of x or y is true, else returns false. |
NOT | ! | !x | Returns true if x is false, or false if x is true. |
Kotlin Program to demonstrate Logical Operators
In the following program, we take boolean values in a
, and b
; and perform logical operations on these values.
Kotlin Program
fun main() {
val x = true
val y = false
// AND Operation
val xAndY = x && y
// OR Operation
val xOrY = x || y
// NOT Operation
val notX = !x
println("x && y = $xAndY")
println("x || y = $xOrY")
println("!x = $notX")
}
Output
x && y = false
x || y = true
!x = false
Logical Operators Tutorials
The following tutorials cover Logical Operators in detail with syntax and examples.