CS Electrical And Electronics
@cselectricalandelectronics

What is "When" Keyword in Kotlin?

All QuestionsCategory: KotlinWhat is "When" Keyword in Kotlin?
chetan shidling asked 3 years ago

I need short information.

1 Answers
chetan shidling answered 3 years ago

when keyword is like switch keyword in C language. Below is the code, how to use when keyword in Kotlin.

fun main(args:Array<String>){
val num : Int = 2

when(num)
{
1 -> println(“It is one”)
2 -> println(“It is two”)
3 -> println(“It is three”)
4 -> println(“It is four”)
else -> println(“Give the proper input”)
}
}