Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: for for/else clarify that return or raise also skip the else #124591

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
nedbat marked this conversation as resolved.
Show resolved Hide resolved
execution of the :keyword:`else` clause.

This is exemplified in the following :keyword:`!for` loop,
which searches for prime numbers::
Expand Down
Loading