[Python-Dev] PEP 315 - do while

Hans Polak Hans.Polak at capgemini.com
Tue Oct 3 17:17:36 CEST 2006

Please note that until <==> while not.

	until count > 10

	while count <= 10


-----Original Message-----
From: Michael Foord [mailto:fuzzyman at gmail.com] On Behalf Of Fuzzyman
Sent: martes, 03 de octubre de 2006 16:29
To: Nick Coghlan
Cc: Hans Polak; python-dev at python.org
Subject: Re: [Python-Dev] PEP 315 - do while

Nick Coghlan wrote:

> [snip..]
>> The current idiom works fine, but looks unnatural :
>> while True:
>>     if <condition>:
>>        break
> There's the rationale for the PEP in a whole 5 lines counting
> whitespace ;)
>> Would a 'while' outside of a 'do' block (but without the colon) then be
>> a syntax error ?
>> 'do:' would just be syntactic sugar for 'while True:' I guess.
> That's the slight issue I still have with the idea - you could end up
> with multiple ways of spelling some of the basic loop forms, such as
> these 3 flavours of infinite loop:
>   do:
>       pass # Is there an implicit 'while True' at the end of the loop
> body?
>   do:
>       while True
>   while True:
>       pass
Following the current idiom, isn't it more natural to repeat the loop
'until' a condition is met. If we introduced two new keywords, it would
avoid ambiguity in the use of 'while'.

    <loop body>
    until <condition>

A do loop could require an 'until', meaning 'do' is not *just* a
replacement for an infinite loop. (Assuming the parser can be coerced
into co-operation.)

It is obviously still a new construct in terms of Python syntax (not
requiring a colon after '<condition>'.)

I'm sure this has been suggested, but wonder if it has already been
ruled out. An 'else' block could then retain its current meaning
(execute if the loop is not terminated early by an explicit  break.)

Michael Foord

This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient,  you are not authorized to read, print, retain, copy, disseminate,  distribute, or use this message or any part thereof. If you receive this  message in error, please notify the sender immediately and delete all  copies of this message.

More information about the Python-Dev mailing list