Kotlin - Control Flow
If - Else Kotlin is a functional language hence like every functional language in Kotlin “ if ” is an expression, it is not a keyword. The expression “if” will return a value whenever necessary . Like other programming language, “ if-else ” block is used as an initial conditional checking operator. In the following example, we will compare two variables and provide the required output accordingly. fun main (args: Array<String>) { val a:Int= 5 val b:Int= 2 var max: Int if (a > b) { max = a } else { max = b } print( "Maximum of" +max) As expression val max = if (a > b) a else b } The above piece of code yields the following output as a result in the browser. Our example also contains another line of code, which depicts how to use “ If ” statement as an expression. Use of When If you are famili...