https://kotlinlang.org logo
Title
s

standinga

07/30/2019, 4:04 PM
when (i) {
in 0..10 -> //
in 10..20 -> //
}
c

Casey Brooks

07/30/2019, 4:05 PM
Just move the
i
into the condition statements
when {
    i in 0..10 -> //
    i in 10..20 -> //
}
s

standinga

07/30/2019, 4:06 PM
great! Thank you
I've googled when / ranges and haven't posts mentioning this solution.
a

Aleksei Otts

07/30/2019, 4:07 PM
you just need to add
else ->
block
s

standinga

07/30/2019, 4:07 PM
yeah, this I knew already 🙂
a

Aleksei Otts

07/30/2019, 4:07 PM
¯\_(ツ)_/¯
c

Casey Brooks

07/30/2019, 4:09 PM
only if you’re assigning the
when
to a variable as an expression, do the branches need to be exhaustive. If it’s just a bare
when
statement, it doesn’t need to be exhaustive
s

standinga

07/30/2019, 4:10 PM
yeah, although I have else case (in my case :)
m

mathew murphy

07/30/2019, 4:33 PM
BTW the ranges overlapping is intentional, right?
f

fangzhzh

07/31/2019, 7:32 PM
if i is 10, where does it go? first or second or both?