``` when (i) { in 0..10 -> // in 10..20 -> /...
# announcements
s
Copy code
when (i) {
in 0..10 -> //
in 10..20 -> //
}
c
Just move the
i
into the condition statements
Copy code
when {
    i in 0..10 -> //
    i in 10..20 -> //
}
s
great! Thank you
I've googled when / ranges and haven't posts mentioning this solution.
a
you just need to add
else ->
block
s
yeah, this I knew already 🙂
a
¯\_(ツ)_/¯
c
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
yeah, although I have else case (in my case :)
m
BTW the ranges overlapping is intentional, right?
f
if i is 10, where does it go? first or second or both?