[Python-ideas] Updating PEP 315: do-while loops

Stefan Behnel stefan_ml at behnel.de
Sun Apr 26 09:45:08 CEST 2009


Larry Hastings wrote:
> Chris Rebert wrote:
>> I don't see why the if-as-suffix is needed when we already have a
>> one-liner for such situations (e.g.):
>>
>> if i != '1': break
>>
>> It's much more uniform and only one character longer.
>>   
> 
> I certainly see your point.  Let me take it a step further: the "do: ...
> while <condition>" construct isn't needed, given that it's already
> expressible with "while True: ... if not <condition>: break".

Hmm, so why add another keyword like "do", instead of just giving "while" a
default condition "True", so that you could write

    while:
        state = do_stuff_here()
        if predicate(state): break

I think that the missing condition at the top makes it pretty clear that
the end condition must be inside the loop.

Stefan




More information about the Python-ideas mailing list