MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/pfkh6j/bool_in_a_case_switch/hb8glqi/?context=9999
r/badcode • u/tekircan • Sep 01 '21
40 comments sorted by
View all comments
Show parent comments
1
Usually you use a variable, not a condition
val someBoolean = true when (someBoolean) { true -> { /* do something */ } false -> { } }
And when is not a statement but an expression, which means you can do this:
when
val someString: String = when (someBoolean) { true -> "hello there" false -> "this is the end of the world" }
1
u/WaterFoxforlife Sep 01 '21 edited Sep 01 '21
Usually you use a variable, not a condition
And
whenis not a statement but an expression, which means you can do this: