[Python-ideas] Immemorial desire for "do-while"-like construction

Carl Johnson cmjohnson.mailinglist at gmail.com
Thu Jul 16 02:47:10 CEST 2009

On Wed, Jul 15, 2009 at 2:16 PM, Jan Kaliszewski<zuo at chopin.edu.pl> wrote:
> 16-07-2009 o 00:54 Chris Rebert <pyideas at rebertia.com> wrote:
>> You can fix that by just writing it as:
>> while True:
>>    SOME
>>    HERE
>>    if not CONDITION: break
> Yeah, but it's not the same :) because eyes must look for the actual loop
> condition somewhere-within-the-loop (after all, "while True" is common
> idiom with large field of usage, not only in such situations...).

I think we can just piggyback off of Python's existing optional
support for braces, BEGIN, END, etc.:

while True: #DO WHILE COND {
# }
    if cond: break


My favorite proposal out of the last discussion of do-while was to
make "while:" mean "while True:". Combined with Python's optional
support for braces, it sounds like a winner to me! :-D


-- Carl Johnson

More information about the Python-ideas mailing list