Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"while"'s "break" could return value #446

Open
funny-falcon opened this issue Aug 29, 2022 · 1 comment
Open

"while"'s "break" could return value #446

funny-falcon opened this issue Aug 29, 2022 · 1 comment

Comments

@funny-falcon
Copy link

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".
@baszalmstra
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants