Control flow based Kotlin interview questions and answers
if Expression Why Doesn’t Kotlin Feature Explicit Ternary Conditionals? Kotlin doesn’t offer any specific ternary operator of the form c = (a < b) ? a : b; like Java or C. It omits this option because you can do the same with the if expression in Kotlin. Since the above ternary operator is essentially an expression of the form (condition ? then : else) , Kotlin simply allows you to do this using its standard if keyword. val c = if (a < b) a else b This line of code does the same thing in Kotlin as the ternary operator does in Java. You can also pack blocks inside if-else branches. when Expression What is the equivalent of switch expression in Kotlin? How does it differ from switch? when is the equivalent of switch in Kotlin . The default statement in a when is represented using the else statement. var num = 10 when (num) { 0. .4 -> print ( "value is 0" ) 5 -> print ( "value is 5" ) else -> { print ( "value is in neither of the abo...