Kotlin OR

Kotlin OR Operator

Kotlin OR Operator || returns the result of the logical OR gate operation for the given two operands.

Syntax

The syntax to use logical OR operator is

x || y

where

  • x is the left operand
  • || is the symbol used for OR logical operator
  • y is the right operand

Return Value

The above expression returns true if at least one of the x or y are true.

Chaining of OR Operator

We can also chain the OR operator to perform the logical OR gate operation with more than two inputs.

x || y || z

You can add as many inputs (boolean values) in a single expression as you would like by chaining the logical OR operator as shown in the above expression.

OR Truth Table

The output of logic OR gate operation with two operands x and y is given in the following table.

xyx || y
truetruetrue
truefalsetrue
falsetruetrue
falsefalsefalse
Truth table of logical OR operation for inputs: x, y

Examples

OR of true, false

In the following program, we take two variables: x, and y with the values true and false respectively; give them as inputs to logical OR operator, and find out the result.

Kotlin Program

fun main() {
    val x = true
    val y = false
    val result = x || y
    println("x || y = $result")
}

Output

x || y = true

OR of false, false

In the following program, we take two false in the variables x, and y, given them as input to logical OR operator, and find out the result.

Kotlin Program

fun main() {
    val x = false
    val y = false
    val result = x || y
    println("x || y = $result")
}

Output

x || y = false