When Expression
Learn how Kotlin uses the powerful when expression for multiple conditions.
Kotlin Code
Study the example and understand each part.
fun main() {
val day = 2
when (day) {
1 -> println("Monday")
2 -> println("Tuesday")
3 -> println("Wednesday")
4 -> println("Thursday")
5 -> println("Friday")
else -> println("Weekend")
}
}
Kotlin is commonly developed using Android Studio or IntelliJ IDEA. These examples can be used as a foundation for Android application development.
Key Concept
The when expression is especially useful when an application has several possible conditions.
Expected Output / Result
Tuesday
Finished this lesson?
Mark it complete to update your course progress.