[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 5329d1b74a)

Co-authored-by: Ned Batchelder <ned@nedbatchelder.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-09-27 20:08:56 +02:00 committed by GitHub
parent f6e23bb6bb
commit ac3e6f801b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 2 deletions

View 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::