I often see people write that `when` without an ar...
# getting-started
f
I often see people write that
when
without an argument is a replacement for an
if-else-if
ladder. But why particularly the argument-less one? Isn't it also a replacement for
if-else-if
when it has an argument?
s
I think
when
looks nicer. What's more, in the case of
Copy code
if (a > 0) {}
else if (b > 0) {}
else {}
it can be a little bit more difficult to pass one variable.
f
What I mean is
The Kotlin docs say "when without an argument replaces the if-else-if ladder"
and every article online seems to copy that wording
but a normal when statement with an argument also works like an if-else-if, doesn't it?
m
yes, but
if
does not take an argument, so the comparison with the zero-argument
when
is a closer match
f
That makes a lot of sense, thank you