[Python-Dev] Wishlist: dowhile
Guido van Rossum
gvanrossum at gmail.com
Mon Jun 13 16:41:45 CEST 2005
> > [BJörn Lindqvist]
> >
> >>I would like to have do-while's like this:
> >>
> >>do:
> >> <body>
> >> until <cond>
> >>
> >>But I'm sure that has problems too.
> >
[Raymond Hettinger]
> > That looks nice to me.
[Nick Coghlan]
> And this could easily be extended to allow code both before and after
> the 'until', giving a fully general loop:
>
> do:
> <body-1-or-more-times>
> until <cond>
> <body-0-or-more-times>
> else:
> <on-natural-loop-exit>
Which is exactly like PEP 315 except there 'until' must be spelled
'while not' and the while is properly indented.
(I'm still not sure whether BJörn *meant* the 'until' to be indented
or whether he simply made a mistake; his proposal resembles a Pythonic
version of Pascal's repeat-until, which would have an unindented
until-clause.)
> The 'until' is less hidden than the 'yield' that turns a function into
> a generator, and its presence is obviously signalled by the preceding
> 'do'. Its also less hidden than the 'if'/'break' construct in the
> infinite loop workaround, and about as hidden as the exit flag in the
> other style of workaround (although the 'until' can be more easily
> picked out by a syntax highlighter).
Why are you so excited about having until indented? You didn't give
any examples with multiple occurrences. A single occurrence works just
fine unindented, as PEP 315 has already shown.
The indented until sounds like unnecessary syntactic sugar for 'if X:
break' -- not very Pythonic.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list