From 0a09f3e2c32677b30414a3af93b9bc1841606326 Mon Sep 17 00:00:00 2001 From: Nick Coghlan Date: Thu, 7 Jun 2012 22:57:35 +1000 Subject: [PATCH] Nudge readers towards a more accurate mental model for loop else clauses (Backport from 3.x) --- Doc/tutorial/controlflow.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst index 24c02eb2a97..59b7fff196a 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: