Is there a concise way to check the next statement...
# announcements
a
Is there a concise way to check the next statement, sort of:
Copy code
return when {
    cond1 -> try { something() } catch (e: Exception) { TODO() /* Goto cond2 */ }
    cond2 -> TODO()
    else -> throw RuntimeException("Whatever reason")
}
m
I’d put it in a function and call recursively 🤔
a
So that checks cond1 again blob thinking upside down
m
Ah, mixed it up with
condX
being objects 😅 Anyway, there is no goto or fall-through in Kotlin.
👀 1
You could put the code for
cond2
branch in a local function and simply call it:
onCond2()
👍 1
e
at some point JB was considering using `continue`/`break` keywords inside
when
- and the keywords were reserved for future use and you couldn't use them - but they've abandoned that
😮 1
r
I am so glad they chose not to do that.
break
and
continue
, and
switch
fall through, were generally a good indication that someone was writing code that would be hard to maintain and reason about.
💯 4