Kotlin 2 · Basics and null safety

Branch with when

when is a flexible switch that can be an expression.

val label = when (score) {
    in 0..49 -> "low"
    in 50..89 -> "ok"
    else -> "high"
}

Official Kotlin 2 documentation

More basics and null safety commands

All basics and null safety commands · Kotlin 2 cheatsheet

Was this page helpful?