PEP-0315--Enhanced While Loop: An idea for an alternative syntax

Andrew Clover and-google at doxdesk.com
Wed Feb 18 11:39:32 EST 2004


Andrew Koenig <ark at acm.org> wrote:

>     while:
>         x = foo()
>     and while x != 0:
>         bar(x)

This is the best syntax I've seen suggested so far. Tentatively +1
(shouldn't cause any parser difficulties should it?); the lack of new
keywords is a plus too.

> 'or while' -

>     while True:
>         if <condition 1>:
>             <statements 1>
>         elif <condition 2>:
>             <statements 2>

Shouldn't this logically be 'else while' then? 'or while' would imply to
me that there was fall-through from <statements 1> to <statements 2>. I
suppose 'else while' could cause confusion with Python's while...else
construct though.

Not sure this would see a lot of use; I can't think of the last time I used
a structure like that.

Here's another construct suggested by 'and while':

  if x is not None:
    x.connect()
    q= x.fetch()
  and if len(q)>=1:
    a= q[0]
  else:
    raise Foo() # one of the previous conditions was False

-- 
Andrew Clover
mailto:and at doxdesk.com
http://www.doxdesk.com/



More information about the Python-list mailing list