[Python-Dev] PEP 351 - do while

Ron Adam rrr at ronadam.com
Sun Oct 1 21:08:45 CEST 2006

Michael Urman wrote:
> On 10/1/06, Ron Adam <rrr at ronadam.com> wrote:
>> (I don't think this has been suggested yet.)
>>      while <enter_condition>, <exit_condition>:
>>         <body>
> [snip]
>> Putting both the entry and exit conditions at the top is easier to read.
> I agree in principle, but I thought the proposed syntax already has
> meaning today (as it turns out, parentheses are required to make a
> tuple in a while condition, at least in 2.4 and 2.5). To help stave
> off similar confusion I'd rather see a pseudo-keyword added. However
> my first candidate "until" seems to apply a negation to the exit
> condition.
>     while True until False:  # run once? run forever?
>     while True until True:  # run forever? run once?
 > It's still very different from any syntactical syntax I can think of
 > in python. I'm not sure I like the idea.
 > Michael

I thought the comma might be a sticking point.

My first thought was to have a series of conditions evaluated on loops with the 
last condition repeated.

       while loop1_cond, loop2_cond, loop3_cond, ..., rest_condition:

But I couldn't think of good uses past the first two that are obvious so I 
trimmed it down to just enter_condition and exit_condition which keeps it 
simple.  But from this example you can see they are all really just top of the 
loop tests done in sequence.  A do loop is just a matter of having the first one 
evaluate as True.

The current while condition is an entry condition the first time it's evaluated 
and an exit condition on the rest.  So by splitting it in two, we can specify an 
enter and exit test more explicitly.  There's a certain consistency I like about 
this also.

Is it just getting around or finding a nice alternative to the comma that is the 
biggest problem with this?

Maybe just using "then" would work?

      while cond1 then cond2:


More information about the Python-Dev mailing list