]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] Docs: for for/else clarify that return or raise also skip the else (GH-124591...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 30 Sep 2024 21:17:16 +0000 (23:17 +0200)
committerGitHub <noreply@github.com>
Mon, 30 Sep 2024 21:17:16 +0000 (14:17 -0700)
Docs: for for/else clarify that return or raise also skip the else (GH-124591)

(cherry picked from commit 5329d1b74a86b3a22ff36f7976bfe720ee06d10d)

Co-authored-by: Ned Batchelder <ned@nedbatchelder.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Doc/tutorial/controlflow.rst

index c97c65f7a3988ed48d46bebfdcd9a2e7b318f814..fd765e58ff2485ec0b2c2d79372a2f92984d05ab 100644 (file)
@@ -209,8 +209,10 @@ after the loop finishes its final iteration, that is, if no break occurred.
 
 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`.
+In either kind of loop, the :keyword:`!else` clause is **not** executed if the
+loop was terminated by a :keyword:`break`.  Of course, other ways of ending the
+loop early, such as a :keyword:`return` or a raised exception, will also skip
+execution of the :keyword:`else` clause.
 
 This is exemplified in the following :keyword:`!for` loop,
 which searches for prime numbers::