3 ms·
Does the following also have "semantics identical to goto"? // functional lands data EC = Situation1 | ... | SituationN case (Expr0) of S
by Joker_vD 2y ago
Does the following also have "semantics identical to goto"?
// functional lands
data EC = Situation1 | ... | SituationN
case (Expr0) of
Situation1 -> IOAction1
...
SituationN -> IOActionN
// imperative lands
type Outcome int
const Situation1 Outcome = iota, Situation2, ... SituationN
var outcome Outcome
for {
... { outcome = Situation1; break }
... { outcome = SituationN; break }
}
switch outcome {
case Situation1:
<statements1>
...
case SituationN:
<statementsN>
}
I personally don't think so, Zahn's construct is merely a way to succinctly express such a switch in the control flow. In fact, Rust almost has it, with its loops being expressions.
- immibis 2y agoYes? This is making the code worse in order to dogmatically avoid goto.