Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ac3e6f8

Browse files
miss-islingtonnedbatJelleZijlstra
authored
[3.13] Docs: for for/else clarify that return or raise also skip the else (GH-124591) (#124659)
Docs: for for/else clarify that return or raise also skip the else (GH-124591) (cherry picked from commit 5329d1b) Co-authored-by: Ned Batchelder <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]>
1 parent f6e23bb commit ac3e6f8

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Doc/tutorial/controlflow.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,10 @@ after the loop finishes its final iteration, that is, if no break occurred.
209209

210210
In a :keyword:`while` loop, it's executed after the loop's condition becomes false.
211211

212-
In either kind of loop, the :keyword:`!else` clause is **not** executed
213-
if the loop was terminated by a :keyword:`break`.
212+
In either kind of loop, the :keyword:`!else` clause is **not** executed if the
213+
loop was terminated by a :keyword:`break`. Of course, other ways of ending the
214+
loop early, such as a :keyword:`return` or a raised exception, will also skip
215+
execution of the :keyword:`else` clause.
214216

215217
This is exemplified in the following :keyword:`!for` loop,
216218
which searches for prime numbers::

0 commit comments

Comments
 (0)