When is not a function, but an expression (#4603)

https://kotlinlang.org/docs/control-flow.html#when-expression
This commit is contained in:
Stefan Lobbenmeier 2023-08-25 05:55:03 +02:00 committed by GitHub
parent 63a2c26029
commit a0736c7a17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -297,7 +297,7 @@ fun helloWorld(val name : String) {
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) {
0, 21 -> "0 or 21"
in 1..20 -> "in the range 1 to 20"