-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
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
gh-123786: Clarify else
clause in loop statements
#123787
base: main
Are you sure you want to change the base?
Conversation
…t be paired with a break
Can you add the issue number to the title? |
In either kind of loop, the :keyword:`!else` clause is **not** executed | ||
if the loop was terminated by a :keyword:`break`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should keep this sentence. It underscores the semantics.
|
||
In a :keyword:`for` loop, the :keyword:`!else` clause is executed | ||
after the loop reaches its final iteration. | ||
after the loop reaches its final iteration if no break occurred. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after the loop reaches its final iteration if no break occurred. | |
after the loop finishes its final iteration, that is, if no break occurred. |
I think this is clearer.
@@ -166,15 +166,13 @@ arguments. In chapter :ref:`tut-structures`, we will discuss in more detail abo | |||
The :keyword:`break` statement breaks out of the innermost enclosing | |||
:keyword:`for` or :keyword:`while` loop. | |||
|
|||
A :keyword:`!for` or :keyword:`!while` loop can include an :keyword:`!else` clause. | |||
The :keyword:`!break` statement may be paired with an :keyword:`!else` clause. | |||
If the loop exits without executing the break, the else clause executes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the loop exits without executing the break, the else clause executes. | |
If the loop finishes without executing the break, the else clause executes. |
I've made a larger change to this section, including these changes, in #123946 |
else
branch of aloop
statement #123786📚 Documentation preview 📚: https://cpython-previews--123787.org.readthedocs.build/