8000 better structuring of the "else" explanation · python/cpython@5d08a1b · GitHub
[go: up one dir, main page]

Skip to content

Commit 5d08a1b

Browse files
committed
better structuring of the "else" explanation
1 parent 6acff0c commit 5d08a1b

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

Doc/tutorial/controlflow.rst

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,18 @@ arguments. In chapter :ref:`tut-structures`, we will discuss in more detail abo
166166
The :keyword:`break` statement breaks out of the innermost enclosing
167167
:keyword:`for` or :keyword:`while` loop.
168168

169-
The :keyword:`for` loop statements may have an extra :keyword:`!else` clause;
170-
it is executed when the loop terminates through exhaustion of the iterable
171-
(with :keyword:`for`) or when the condition becomes false (with :keyword:`while`),
172-
but not when the loop is terminated by a :keyword:`break` statement.
173-
This is exemplified by the following loop, which searches for prime numbers::
169+
A :keyword:`for` or :keyword:`while` loop can include an 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)
0