[Python-Dev] Wishlist: dowhile
Josiah Carlson
jcarlson at uci.edu
Mon Jun 13 06:37:30 CEST 2005
Nick Coghlan <ncoghlan at gmail.com> wrote:
>
> Raymond Hettinger wrote:
> > More than case-statement semantics or PEP343, I wish for a dowhile
> > statement.
> >
> > The most straight-forward way is to put the conditional expression at
> > the beginning of the block with the understanding that a dowhile keyword
> > will evaluate the condition only after the block runs
>
> Out-of-order code execution rarely counts as 'straightforward' ;)
>
> With PEP 315, a do-while loop would look like:
>
> do:
> <body>
> while <cond>:
> pass
>
> But then, I'm reasonably happy with the 'break out of an infinite
> loop' approach, so *shrug*.
PEP 315 offers the creation/use of an additional keyword. It also
happens to push the condition to the end of the loop body.
I'm not sure that pushing condition evaluation to the end of the loop
body (with a trailing 'pass' as provided) is necessarily more readable
than Raymond's offered dowhile. In fact, if I remember the discussion
over decorators correctly, putting an operation later actually reduces
readability, though at least in this case, the bare "do:" would signal
to the user "Hey, I have a condition later!" Though we again run into,
how is that any better than having the condition at the front to begin
with, especially if a new keyword is necessary regardless of the
resulting syntax?
- Josiah
More information about the Python-Dev
mailing list