Skip to content

Commit 7d41487

Browse files
[3.11] gh-107017: removed mention that C does it the same way (GH-107020) (#107098)
Co-authored-by: Jakub Červinka <cervinka.jakub.1989@gmail.com>
1 parent 9875b17 commit 7d41487

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

Doc/tutorial/controlflow.rst

+15-8
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
More Control Flow Tools
55
***********************
66

7-
Besides the :keyword:`while` statement just introduced, Python uses the usual
8-
flow control statements known from other languages, with some twists.
7+
As well as the :keyword:`while` statement just introduced, Python uses a few more
8+
that we will encounter in this chapter.
99

1010

1111
.. _tut-if:
@@ -163,14 +163,21 @@ arguments. In chapter :ref:`tut-structures`, we will discuss in more detail abo
163163
:keyword:`!break` and :keyword:`!continue` Statements, and :keyword:`!else` Clauses on Loops
164164
============================================================================================
165165

166-
The :keyword:`break` statement, like in C, breaks out of the innermost enclosing
166+
The :keyword:`break` statement breaks out of the innermost enclosing
167167
:keyword:`for` or :keyword:`while` loop.
168168

169-
Loop statements may have an :keyword:`!else` clause; it is executed when the loop
170-
terminates through exhaustion of the iterable (with :keyword:`for`) or when the
171-
condition becomes false (with :keyword:`while`), but not when the loop is
172-
terminated by a :keyword:`break` statement. This is exemplified by the
173-
following loop, which searches for prime numbers::
169+
A :keyword:`!for` or :keyword:`!while` loop can include an :keyword:`!else` clause.
170+
171+
In a :keyword:`for` loop, the :keyword:`!else` clause is executed
172+
after the loop reaches its final iteration.
173+
174+
In a :keyword:`while` loop, it's executed after the loop's condition becomes false.
175+
176+
In either kind of loop, the :keyword:`!else` clause is **not** executed
177+
if the loop was terminated by a :keyword:`break`.
178+
179+
This is exemplified in the following :keyword:`!for` loop,
180+
which searches for prime numbers::
174181

175182
>>> for n in range(2, 10):
176183
... for x in range(2, n):

0 commit comments

Comments
 (0)