[Python-Dev] Wishlist: dowhile

BJörn Lindqvist bjourne at gmail.com
Tue Jun 14 20:24:44 CEST 2005


> > do:
> >     <block>
> > until <cond>
> >
> > Written like this it is not very obvious that the 'unil' is part of
> > the do-until suite. I also imagine it to be difficult to parse and it
> > breaks the rule that suites end when there is a dedentation. So, IMHO
> > using an indented 'until' is the least evil of a number of evils.
> 
> Not difficult to parse at all, nor un-Pythonic. Multi-part blocks
> abound in Python: if / elif / else, try / finally, etc.

Oh. I had the impression that the reason do-while's (or do-until's
which I like more) wasn't implemented in the language was because it
was impossible to find an acceptable looking syntax.

 > > Yes, but grepping the stdlib produces over 300 hits for "while 1:" and
> > "while True:" combined. Some of those a "if <cond>: break" in the
> > middle and some would be better written as generators, but lots of
> > them would be rewritten as do-while's. So I think there is more than
> > enough use cases for syntactic sugar for do-while loops.
> 
> The PEP 315 solution looks much better than an "until" that isn't what
> it looks like.

What do you mean by that? The proposed until would work exactly like
it do in languages that support until loops. I'm also reasonably happy
with PEP 315, except that it seems to force you to end it with a pass
if the condition is last in the loop. But is discussing do-while's
beating a dead horse or is there a possibility that do-while's will
someday make it into the language?

-- 
mvh Björn


More information about the Python-Dev mailing list