mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-08 07:46:46 +02:00
When is not a function, but an expression (#4603)
https://kotlinlang.org/docs/control-flow.html#when-expression
This commit is contained in:
committed by
GitHub
parent
63a2c26029
commit
a0736c7a17
@@ -297,7 +297,7 @@ fun helloWorld(val name : String) {
|
|||||||
else -> println("none of the above")
|
else -> println("none of the above")
|
||||||
}
|
}
|
||||||
|
|
||||||
// "when" can be used as a function that returns a value.
|
// "when" can be used as an expression that returns a value.
|
||||||
var result = when (i) {
|
var result = when (i) {
|
||||||
0, 21 -> "0 or 21"
|
0, 21 -> "0 or 21"
|
||||||
in 1..20 -> "in the range 1 to 20"
|
in 1..20 -> "in the range 1 to 20"
|
||||||
|
Reference in New Issue
Block a user