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

Andrew Clover and-google at
Wed Feb 18 17:39:32 CET 2004

Andrew Koenig <ark at> 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:
    q= x.fetch()
  and if len(q)>=1:
    a= q[0]
    raise Foo() # one of the previous conditions was False

Andrew Clover
mailto:and at

More information about the Python-list mailing list