From: Nick Coghlan Date: Thu, 7 Jun 2012 12:41:34 +0000 (+1000) Subject: Nudge readers towards a more accurate mental model for loop else clauses X-Git-Tag: v3.3.0b1~262^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a3a164a03c78d66539f4fe9abf8d1dd5c08babaa;p=thirdparty%2FPython%2Fcpython.git Nudge readers towards a more accurate mental model for loop else clauses --- diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst index 5ed5aea44498..902f2bd48c91 100644 --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -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: