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

Josiah Carlson josiah.carlson at gmail.com
Sun Apr 26 07:06:14 CEST 2009

On Sat, Apr 25, 2009 at 7:39 PM, Raymond Hettinger <python at rcn.com> wrote:
> [Eric Smith]
>> You might want to note in the PEP that the problem that's being solved is
>> known as the "loop and a half" problem, at least for your motivating case
>> #2.
> Thanks.  When I update the PEP, will add that link.
> Wanted to get people's reaction here first.
> Do the condition-at-the-top format work for everyone
> or can someone think-up a condition-at-the-bottom
> approach the doesn't suck with respect to existing
> Python syntax.

Condition at the bottom sucks for similar reasons as why ...
def foo(...):
    (many lines of code)
foo = classmethod(foo)

Having your condition, modification, etc., at the end is just plain
annoying.  I like my conditions up top.

I agree with you that the 3-suite do/while/else option is just plain
ugly.  I also agree that the "do while <condition>:" variants are
currently the prettiest, but it still doesn't feel quite right to me.

When confronted with these things, I usually go for the "while True"
or "while first or <condition>" versions, and throw a comment just
before the condition in the "while True" variant so my eye is drawn

 - Josiah

More information about the Python-ideas mailing list