From ac3e6f801be42b0d2691a19dc3c289faa67f628f Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Fri, 27 Sep 2024 20:08:56 +0200 Subject: [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 5329d1b74a86b3a22ff36f7976bfe720ee06d10d) Co-authored-by: Ned Batchelder Co-authored-by: Jelle Zijlstra --- Doc/tutorial/controlflow.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst index c97c65f..fd765e5 100644 --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -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:: -- cgit v0.12