KotlinSyntax
When Expression
Code example
when (n) {
1 -> "one"
else -> "other"
}Matches a value against cases.
In Kotlin, when expression: matches a value against cases — when (n) { 1 -> "one" else -> "other" }
when (n) {
1 -> "one"
else -> "other"
}when (n) {
1 -> "one"
else -> "other"
}Matches a value against cases.
Use when (n) { 1 -> "one" else -> "other" }.
Use this pattern: when (n) { 1 -> "one" else -> "other" }
Yes. Use Copy code and adapt the example to your program.
No. The language syntax is the same across operating systems.