-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-123786: Clarify else
clause in loop statements
#123787
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0c0df28
Draft
gweatherby cdbb517
Rephrase to make each sentence true by itself. Emphasize the else musβ¦
Gerardwx d139a22
Remove trailing whitespace
Gerardwx ea20080
Merge branch 'main' into for-else
Gerardwx 9538941
Issue #123786
Gerardwx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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. | ||||||
|
||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think this is clearer. |
||||||
|
||||||
In a :keyword:`while` loop, it's executed after the loop's condition becomes false. | ||||||
|
||||||
In either kind of loop, the :keyword:`!else` clause is **not** executed | ||||||
if the loop was terminated by a :keyword:`break`. | ||||||
Comment on lines
-176
to
-177
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should keep this sentence. It underscores the semantics. |
||||||
In a :keyword:`while` loop, it's executed after the loop's condition becomes false if no break occurred. | ||||||
|
||||||
This is exemplified in the following :keyword:`!for` loop, | ||||||
which searches for prime numbers:: | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.