Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

The || operator in Kotlin performs a logical disjunction (OR) between two Boolean expressions. It evaluates to true if at least one of the operands is true, and false strictly when both operands are false.
val result = expression1 || expression2

Technical Characteristics

1. Short-Circuit Evaluation Kotlin implements lazy evaluation for the || operator. The compiler evaluates the left-hand side (LHS) expression first. If the LHS evaluates to true, the overall expression is guaranteed to be true, and the right-hand side (RHS) expression is never evaluated. The RHS is only evaluated if the LHS evaluates to false. 2. Type Constraints Both operands must resolve to the Boolean type. Kotlin does not support implicit truthiness (e.g., evaluating integers or null references as booleans). 3. Operator Precedence The || operator has lower precedence than the logical AND operator (&&) and equality operators (==, !=), but higher precedence than assignment operators (=, +=). 4. Non-Overloadable Unlike arithmetic operators or the bitwise or infix function, the || operator cannot be overloaded via operator overloading. This restriction exists because short-circuiting is a compiler-level control flow mechanism, not a standard function call.

Truth Table and Evaluation Path

Left Operand (LHS)Right Operand (RHS)Evaluation PathResult
trueIgnoredLHS onlytrue
falsetrueLHSRHStrue
falsefalseLHSRHSfalse

Syntax Visualization

The following code demonstrates the short-circuiting mechanics using side-effecting functions to visualize execution flow:
fun returnTrueWithLog(): Boolean {
    println("Evaluated RHS")
    return true
}

// LHS is true. RHS is skipped. 
// Output: (No print statement executed)
val a = true || returnTrueWithLog() 

// LHS is false. RHS must be evaluated.
// Output: "Evaluated RHS"
val b = false || returnTrueWithLog()

// Precedence demonstration: && evaluates before ||
// Equivalent to: true || (false && false)
val c = true || false && false 
Master Kotlin with Deep Grasping Methodology!Learn More