[Python-ideas] Nudging beginners towards a more accurate mental model for loop else clauses
jeanpierreda at gmail.com
Sun Jun 10 01:33:21 CEST 2012
On Sat, Jun 9, 2012 at 1:49 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> - If the loop is exited by a return, *nothing* following the return is
> executed. That includes the else block.
> - If execution is halted by an exception (including raise), *nothing*
> following the exception is executed. That includes the else block.
> - If execution is halted by an external event that halts or interrupts the
> Python process, *nothing* following executes. That includes the else block.
> - If the loop never completes, *nothing* following the loop executes. That
> includes the else block.
> To continue the analogy with the "Red Dwarf" quote I made earlier:
Please stop mocking your own writing. I wrote nothing like the above.
I said that maybe we should be specific and correct with when else is
called. I didn't say that we should be exhaustive for when it is not.
In fact, the example explanations I gave were not exhaustive.
More information about the Python-ideas