Wednesday, 6 December 2017

Kotlin Tutorial in Hindi | Logical Operators

There are two logical operators in Kotlin: || and &&
Here's a table of logical operators, their meaning, and corresponding functions.
OperatorDescriptionExpressionCorresponding Function
||true if either of the Boolean expression is true(a>b)||(a<c)(a>b)or(a<c)
&&true if all Boolean expressions are true(a>b)&&(a<c)(a>b)and(a<c)
Note that, or and and are functions that support infix notation.
Logical operators are used in control flow such as if expressionwhen expression, and loops.

Example: Logical Operators

fun main(args: Array<String>) {

    val a = 10
    val b = 9
    val c = -1
    val result: Boolean

    // result is true is a is largest
    result = (a>b) && (a>c) // result = (a>b) and (a>c)
When you run the program, the output will be:

No comments:

Post a Comment