]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Nudge readers towards a more accurate mental model for loop else clauses
authorNick Coghlan <ncoghlan@gmail.com>
Thu, 7 Jun 2012 12:41:34 +0000 (22:41 +1000)
committerNick Coghlan <ncoghlan@gmail.com>
Thu, 7 Jun 2012 12:41:34 +0000 (22:41 +1000)
Doc/tutorial/controlflow.rst

index 5ed5aea44498e3147f5b8342a46d6f9aac30046c..902f2bd48c913582f04bbf45838af644572f30b4 100644 (file)
@@ -187,6 +187,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: