Skip to content

Commit

Permalink
[3.12] Docs: for for/else clarify that return or raise also skip the …
Browse files Browse the repository at this point in the history
…else (GH-124591) (#124660)

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]>
  • Loading branch information
3 people authored Sep 30, 2024
1 parent 660a7f2 commit 7c39f74
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Doc/tutorial/controlflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand Down

0 comments on commit 7c39f74

Please sign in to comment.