summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2012-06-07 12:57:35 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2012-06-07 12:57:35 (GMT)
commit0a09f3e2c32677b30414a3af93b9bc1841606326 (patch)
tree09d305ed473f8813488347f8ca89359c666f27d2
parente93bc51b5982c329a6065eb83ac1dea5efb02bd7 (diff)
downloadcpython-0a09f3e2c32677b30414a3af93b9bc1841606326.zip
cpython-0a09f3e2c32677b30414a3af93b9bc1841606326.tar.gz
cpython-0a09f3e2c32677b30414a3af93b9bc1841606326.tar.bz2
Nudge readers towards a more accurate mental model for loop else clauses (Backport from 3.x)
-rw-r--r--Doc/tutorial/controlflow.rst7
1 files changed, 7 insertions, 0 deletions
diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst
index 24c02eb..59b7fff 100644
--- a/Doc/tutorial/controlflow.rst
+++ b/Doc/tutorial/controlflow.rst
@@ -159,6 +159,13 @@ following loop, which searches for prime numbers::
(Yes, this is the correct code. Look closely: the ``else`` clause belongs to
the :keyword:`for` loop, **not** the :keyword:`if` statement.)
+When used with a loop, the ``else`` clause has more in common with the
+``else`` clause of a :keyword:`try` statement than it does that of
+:keyword:`if` statements: a :keyword:`try` statement's ``else`` clause runs
+when no exception occurs, and a loop's ``else`` clause runs when no ``break``
+occurs. For more on the :keyword:`try` statement and exceptions, see
+:ref:`tut-handling`.
+
.. _tut-pass: