January 2018
Intermediate to advanced
434 pages
14h 1m
English
First, let's create a file, name it whenWithRanges.kt, and follow these steps:
fun main(args: Array<String>) { val x = 12 when(x){ 12 -> println("x is equal to 12") 4 -> println("x is equal to 4") else -> println ("no conditions match!") } }
So basically, this code block works like a switch case statement, and it can also be implemented using an if statement.
fun main(args: Array<String>) { val x = 12 when(x){ in (1..10) -> println("x lies between 1 to 10") !in (1..10) -> println("x does not lie between 1 to 10") } }
Read now
Unlock full access