You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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".
The text was updated successfully, but these errors were encountered:
There is solution to "a
break
in awhile
loop cannot return a value" inspired by Python:while
(andfor
) loop can haveelse:
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-statementThis construction is unusual, rare language has
else
for loops (I don't remember one except Python). Therefore almost nobody uses it.break
may return value from loop" feature (which Python has not). It could sound like:"if
while
's loop body hasbreak
with value, then it has to haveelse
block which results with value of same type".The text was updated successfully, but these errors were encountered: