Re:Designing a Programming Language: I
by Joker_vD on Thursday October 27, 2022 @01:40PM
(#33361162)
There are languages with
while cond1
stmts1
elif cond2
stmts2
elif cond3
stmts3
syntax which is essentially a few if/else blocks pulled up to the enclosing loop level. Makes writing e.g.
while a > b
a := a - b
elsif b > a
b := b - a
somewhat more concise. And Rust's "while let" loop easily could have allowed several clauses instead of single one.
And yes, you can express all of that with either "while true: ..." with early breaks/returns or with "while <OR'ing lots of Boolean flags>: ..." with post-processing those flags to determines why the loop has ended... but why not have explicitly named, limited continuations? Putting every loop into its own function sounds as a "meh" solution to me.
And yes, you can express all of that with either "while true: ..." with early breaks/returns or with "while <OR'ing lots of Boolean flags>: ..." with post-processing those flags to determines why the loop has ended... but why not have explicitly named, limited continuations? Putting every loop into its own function sounds as a "meh" solution to me.