Nobody is arguing against using early returns at a...
# announcements
s
Nobody is arguing against using early returns at all. What we are a bit concerned about is the fact that this code snippet is pretty hard to interpret, and that in of itself may warrant rewriting this block to be more easily understood. That said, sure, in a vacuum “style” does not solve your problem, but it does make it harder to give you advice. Based on your initial snippet, I would suggest something that looks more like this:
Copy code
when (i) {
  in 0..10 -> println("matched")
  else -> println("not matched")
}
println("finished")
n
Nice, but where are returns and labels?
s
if I understand what your needs are correctly, you shouldn’t need a return or label. If
i
is in
0..10
, it will print
matched
, and then exit the
when
block. If
i
is not in that range, you’ll hit the
else
case instead. They will never both be executed
n
Sorry, but no. Code I wrote is just synthetic sample of code which means nothing.