FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-123786: Clarify ``else`` clause in loop statements by Gerardwx · Pull Request #123787 · python/cpython · GitHub

/ cpython Public

gh-123786: Clarify else clause in loop statements - #123787

Closed
Gerardwx wants to merge 5 commits into
python:mainfrom
Gerardwx:for-else
Closed

gh-123786: Clarify else clause in loop statements#123787
Gerardwx wants to merge 5 commits into
python:mainfrom
Gerardwx:for-else

Conversation

Gerardwx commented Sep 6, 2024
edited by picnixz
Loading

Copy link
Copy Markdown
Contributor

ghost commented Sep 6, 2024
edited by ghost
Loading

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

bedevere-app Bot added awaiting review docs Documentation in the Doc dir skip news labels Sep 6, 2024

Copy link
Copy Markdown
Contributor

Can you add the issue number to the title?

Eclips4 changed the title For else gh-123786: Clarify else clause in loop statements Sep 6, 2024
Comment on lines -176 to -177
In either kind of loop, the :keyword:`!else` clause is **not** executed
if the loop was terminated by a :keyword:`break`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
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.


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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
If the loop exits without executing the break, the else clause executes.
If the loop finishes without executing the break, the else clause executes.

nedbat commented Sep 11, 2024

Copy link
Copy Markdown
Member

I've made a larger change to this section, including these changes, in #123946

Gerardwx closed this Mar 10, 2025
Gerardwx deleted the for-else branch March 10, 2025 23:45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL