News for hackers. Stuff that matters.
Re:Designing a Programming Language: I by duped on Thursday October 27, 2022 @01:17PM (#33360831)
I think the reason you won't find this in many languages is because people gravitate towards fewer constructs rather than more, and this syntax can be expressed using more general purpose semantics without any additional cost.

The syntax debate is usually something like, "what does this buy us and do we have the budget for it" and imo that loop syntax is not sufficiently general (it cannot express recursion, for example) nor does it make code easier to read (you now have what's essentially a few if/else blocks split across four different code blocks, I would reject this if I saw it in a code review to make the loop simpler), and it doesn't really prevent a user from making mistakes.

Extremely generic control flow constructs have also been shunned a bit. There's a lot of "call/cc considered harmful" content on the internet from a few years back, and I predict we'll see the same thing about new-fangled control flow constructs like algebraic effects.

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.