1.5.2 for: else:

T. C. Mits 71351.356 at compuserve.com
Sun Aug 1 00:31:22 EDT 1999


ALL:
    I'm a newbie so I may be out of line here, but the for: else: construct
is pretty bad.  It just does not read well, and implies the incorrect
operation; it reminds me of  some of the weird FORTH stuff.   Why not use
another word for this and not overload 'else'?   Maybe for: also:, or
something more in line with the intended purpose.   Sure there may be good
reasons for else that I (newbie) do not know, but I thought Python was
supposed to enable ease of reading, not only writing (ala Perl).

TC Mits.


Hans Nowak <ivnowa at hvision.nl> wrote in message
news:199907272208.AAA06264 at axil.hvision.nl...
>
> On 27 Jul 99, Oleg Broytmann wrote:
>
> > > Loop statements may have an else clause; it is executed when the loop
> > > terminates through exhaustion of the list (with for) or when the
> > > condition becomes false (with while), but not when the loop is
> > > terminated by a break statement. [..]
> > [skip]
> > > Else clauses get executed on normal loop exit, even if the loop was
> > > 'empty'. It does not get executed when you 'break' out of a loop.
> >
> >    Aha, thanks. I expected "else" to be executed when "for" not executed
> >    on
> > empty list. Wrong assumption.
>
> This one has bitten me too in the past. One of the few non-intuitive
> parts of Python, methinks. :(
>
> --Hans Nowak (zephyrfalcon at hvision.nl)
> Homepage: http://fly.to/zephyrfalcon
> Python Snippets: http://www.hvision.nl/~ivnowa/snippets/
> The Purple Kookaburra Forum: http://www.delphi.com/kookaburra/






More information about the Python-list mailing list