PEP-0315--Enhanced While Loop: An idea for an alternative syntax
Robin Munn
rmunn at pobox.com
Thu Feb 19 12:40:36 EST 2004
Andrew Koenig <ark at acm.org> wrote:
> I have a proposal for an alternative syntax that solves both of these
> problems:
>
> while:
> x = foo()
> and while x != 0:
> bar(x)
>
> This example actually incorporates two changes:
>
> 1) "while:" is equivalent to "while True:"
>
> 2) "and while <condition>:" is an exit from the middle of the loop,
> analogously to PEP 315.
I'm -1 on this idea, because "and while" just does not feel Pythonic to
me. I read the code above and see a loop that does "x = foo()" forever,
then when that loop is finished (whenever that may happen) proceeds to
do bar(x) as long as x != 0. In other words, the syntax is very
counter-intuitive to me, and causes me to do a couple of double-takes
before I figure it out.
I've sometimes wished for a construct like do ... while, but I would
rather live without one than have one that's counter-intuitive.
--
Robin Munn
rmunn at pobox.com
More information about the Python-list
mailing list