do ... while loop

Gerrit Holl gerrit.holl at pobox.com
Thu Oct 14 15:34:13 EDT 1999


Tim Peters:
> [Joshua Marcus, fighting initial lack-of-feature bloat <wink>]
> > ...
> > There are, in fact, other situations in which one actually wants a
> > "do...while" loop & one is forced to either repeat code or make a
> > meaningless initial assignment.
> 
> Those are never necessary, although it's amazing how often people fall into
> believing they are.  The usual Python idiom for:
> 
>     do {
>         xxx;
>         yyy;
>     } while (condition);
> 
> is simply:
> 
>     while 1:
>         xxx
>         yyy
>         if not condition:
>             break

Huh?
Why don't use the following code:

while condition:
    xxx
    yyy

I don't understand the difference.

> 
> The criminally insane sometimes write the last line instead as:
> 
>         if not condition: break
> 
> but putting it on separate lines (as God intended) is key to making the
> idiom instantly (after you're used to it -- about two days) recognizable for
> what it is.

I'll change my code. As far as I remember, this isn't mentioned in Guido's
style guide; am I right?

regards,
Gerrit.
-- 
linuxgames.nl.linux.org	 All about games on Linux in Dutch (under construction).
www.nl.linux.org	       The Dutch resource for Dutch Linux documentation.
www.nl.linux.org/discoverb		    Learn foreign words and definitions.
www.nl.linux.org/~gerrit/asperger	 I'm an Asperger, go here for more info.
www.nl.linux.org/~gerrit			    About me and pictures of me.




More information about the Python-list mailing list