mun icon indicating copy to clipboard operation
mun copied to clipboard

"while"'s "break" could return value

Open funny-falcon opened this issue 3 years ago • 1 comments
trafficstars

There is solution to "a break in a while loop cannot return a value" inspired by Python:

  • Python's while (and for) loop can have else: branch that is executed if loop exited with condition and not with break: https://docs.python.org/3.10/reference/compound_stmts.html#the-while-statement This construction is unusual, rare language has else for loops (I don't remember one except Python). Therefore almost nobody uses it.
  • But it could naturally complement "break may return value from loop" feature (which Python has not). It could sound like: "if while's loop body has break with value, then it has to have else block which results with value of same type".

funny-falcon avatar Aug 29 '22 08:08 funny-falcon

Thats an interesting idea! Would you be able to create a PR?

baszalmstra avatar Aug 29 '22 17:08 baszalmstra