gh-107017: removed mention that C does it the same way (#107020)

This commit is contained in:
Jakub Červinka 2023-07-23 10:57:52 +02:00 committed by GitHub
parent 0af247da09
commit 9629d4442e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,8 +4,8 @@
More Control Flow Tools More Control Flow Tools
*********************** ***********************
Besides the :keyword:`while` statement just introduced, Python uses the usual As well as the :keyword:`while` statement just introduced, Python uses a few more
flow control statements known from other languages, with some twists. that we will encounter in this chapter.
.. _tut-if: .. _tut-if:
@ -163,14 +163,21 @@ arguments. In chapter :ref:`tut-structures`, we will discuss in more detail abo
:keyword:`!break` and :keyword:`!continue` Statements, and :keyword:`!else` Clauses on Loops :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. :keyword:`for` or :keyword:`while` loop.
Loop statements may have an :keyword:`!else` clause; it is executed when the loop A :keyword:`!for` or :keyword:`!while` loop can include an :keyword:`!else` clause.
terminates through exhaustion of the iterable (with :keyword:`for`) or when the
condition becomes false (with :keyword:`while`), but not when the loop is In a :keyword:`for` loop, the :keyword:`!else` clause is executed
terminated by a :keyword:`break` statement. This is exemplified by the after the loop reaches its final iteration.
following loop, which searches for prime numbers::
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`.
This is exemplified in the following :keyword:`!for` loop,
which searches for prime numbers::
>>> for n in range(2, 10): >>> for n in range(2, 10):
... for x in range(2, n): ... for x in range(2, n):