Kaydet (Commit) a3a164a0 authored tarafından Nick Coghlan's avatar Nick Coghlan

Nudge readers towards a more accurate mental model for loop else clauses

üst 58f07a9d
...@@ -187,6 +187,13 @@ following loop, which searches for prime numbers:: ...@@ -187,6 +187,13 @@ following loop, which searches for prime numbers::
(Yes, this is the correct code. Look closely: the ``else`` clause belongs to (Yes, this is the correct code. Look closely: the ``else`` clause belongs to
the :keyword:`for` loop, **not** the :keyword:`if` statement.) 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: .. _tut-pass:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment