Feedback on Until recipe

MRAB google at mrabarnett.plus.com
Thu Apr 26 18:30:20 EDT 2007


On Apr 26, 11:58 am, Antoon Pardon <apar... at forel.vub.ac.be> wrote:
> On 2007-04-24, Thomas Nelson <t... at mail.utexas.edu> wrote:
>
> > Occasionally someone posts to this group complaining about the lack of
> > "repeat ... until" in python.  I too have occasionally wished for such
> > a construct, and after some thinking, I came up with the class below.
> > I'm hoping to get some feedback here, and if people besides me think
> > they might use it someday, I can put it on the python cookbook.  I'm
> > pretty happy with it, the only ugly thing is you have to use a
> > lambda.  Ideally i'd like to just see
> > while Until(i<3)
> > but that doesn't work.
> > Please tell me what you think, and thanks for your time.
>
> Maybe we should try to get the developers revive PEP 315.
>
> This PEP whould introduce a do-while statement that looks
> like the folowing:
>
>   do
>     statements
>   while condition
>     statements
>
> this would be equivallent to:
>
>   while 1:
>     statements
>     if not condition:
>       break
>     statements
>
> Those wanting something like:
>
>   repeat
>     statements
>   until condition
>
> Could then write something like:
>
>   do
>     statements
>   while not condition
>     pass
>
> Still not the most elegant but a vast improvement IMO.
>
At http://mail.python.org/pipermail/python-dev/2006-February/060718.html
Raymond Hettinger suggested removing the final colon after the 'while'
if there's no statement after it, which I agree with, although I would
prefer 'repeat' instead of 'do' (IMHO that doesn't suggest repetition
clearly enough):

repeat:
    statements
while condition:
    statements

and:

repeat:
    statements
while condition




More information about the Python-list mailing list