-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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-107017: removed mention that C does it the same way #107020
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5742c7e
removed mention that C does it the same way
JakubDotPy 67534f2
there are no "usual" flow control statements
JakubDotPy a588abc
implemented suggestions
JakubDotPy 6acff0c
fixed typo and a line length
JakubDotPy 5d08a1b
better structuring of the "else" explanation
JakubDotPy e4f676a
removed links
JakubDotPy 9c34614
added keyword formatting
JakubDotPy 8f08838
removed link
JakubDotPy 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 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 |
---|---|---|
|
@@ -4,8 +4,8 @@ | |
More Control Flow Tools | ||
*********************** | ||
|
||
Besides the :keyword:`while` statement just introduced, Python uses the usual | ||
flow control statements known from other languages, with some twists. | ||
As well as the :keyword:`while` statement just introduced, Python uses a few more | ||
that we will encounter in this chapter. | ||
|
||
|
||
.. _tut-if: | ||
|
@@ -163,14 +163,14 @@ | |
:keyword:`!break` and :keyword:`!continue` Statements, and :keyword:`!else` Clauses on Loops | ||
============================================================================================ | ||
|
||
The :keyword:`break` statement, like in C, breaks out of the innermost enclosing | ||
The :keyword:`break` statement breaks out of the innermost enclosing | ||
:keyword:`for` or :keyword:`while` loop. | ||
|
||
Loop statements may have an :keyword:`!else` clause; it is executed when the loop | ||
terminates through exhaustion of the iterable (with :keyword:`for`) or when the | ||
condition becomes false (with :keyword:`while`), but not when the loop is | ||
terminated by a :keyword:`break` statement. This is exemplified by the | ||
following loop, which searches for prime numbers:: | ||
The :keyword:`for` loop statements may have an extra :keyword:`!else` clause; | ||
it is executed when the loop terminates through exhaustion of the iterable | ||
(with :keyword:`for`) or when the condition becomes false (with :keyword:`while`), | ||
but not when the loop is terminated by a :keyword:`break` statement. | ||
This is exemplified by the following loop, which searches for prime numbers:: | ||
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. exemplified in |
||
|
||
>>> for n in range(2, 10): | ||
... for x in range(2, n): | ||
|
@@ -520,7 +520,7 @@ | |
:keyword:`!return` without an expression argument returns ``None``. Falling off | ||
the end of a function also returns ``None``. | ||
|
||
* The statement ``result.append(a)`` calls a *method* of the list object | ||
``result``. A method is a function that 'belongs' to an object and is named | ||
``obj.methodname``, where ``obj`` is some object (this may be an expression), | ||
and ``methodname`` is the name of a method that is defined by the object's type. | ||
|
@@ -1039,7 +1039,7 @@ | |
information about the types used by user-defined functions (see :pep:`3107` and | ||
:pep:`484` for more information). | ||
|
||
:term:`Annotations <function annotation>` are stored in the :attr:`__annotations__` | ||
attribute of the function as a dictionary and have no effect on any other part of the | ||
function. Parameter annotations are defined by a colon after the parameter name, followed | ||
by an expression evaluating to the value of the annotation. Return annotations are | ||
|
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.
I find the original language here rather hard to parse because the concepts are quite unfamiliar (a loop that terminates through exhaustion of an iterable...).
Perhaps:
A for or while loop can include an else clause.
In a for loop, the else clause is executed after the loop reaches its final iteration. In a while loop, it's executed after the loop's condition becomes false.
In either kind of loop, the else clause is not executed if the loop was terminated by a break.