[Python-ideas] for/else syntax
Robert Kern
robert.kern at gmail.com
Fri Oct 2 05:23:27 CEST 2009
Steven D'Aprano wrote:
> On Thu, 1 Oct 2009 09:00:21 pm Antti Rasinen wrote:
>> for x in xs:
>> if cond(x):
>> break
>> # stuff
>> else:
>> # more stuff
>>
>> My code pattern matching algorithm reads that as an indentation
>> error. An else matches if so many times more often that decoding
>> for..else requires unnecessary effort.
>
> But then there are these:
>
> for x in xs:
> if cond(x):
> process()
> else:
> process_differently()
> else:
> do_something_else()
>
>
> for x in xs:
> process()
> else:
> do_something_else()
>
>
> They don't look anything like an indentation error to me.
Am I missing something? Since those examples don't have any break statements in
them, why do you use an else:?
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-ideas
mailing list