summaryrefslogtreecommitdiffstats
path: root/Doc/tutorial
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2024-09-27 10:17:25 (GMT)
committerGitHub <noreply@github.com>2024-09-27 10:17:25 (GMT)
commit5329d1b74a86b3a22ff36f7976bfe720ee06d10d (patch)
tree01778aa0990ec33328870dba0ee9e2e072893b4b /Doc/tutorial
parent3a0e7f57628466aedcaaf6c5ff7c8224f5155a2c (diff)
downloadcpython-5329d1b74a86b3a22ff36f7976bfe720ee06d10d.zip
cpython-5329d1b74a86b3a22ff36f7976bfe720ee06d10d.tar.gz
cpython-5329d1b74a86b3a22ff36f7976bfe720ee06d10d.tar.bz2
Docs: for for/else clarify that return or raise also skip the else (#124591)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Diffstat (limited to 'Doc/tutorial')
-rw-r--r--Doc/tutorial/controlflow.rst6
1 files 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::