do ... while loop
Gordon McMillan
gmcm at hypernet.com
Thu Oct 14 16:07:19 EDT 1999
Gerrit Holl writes:
[Tim Peters]
> > ... 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.
At entry, condition is unknown.
> > 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?
Tim is exaggerating. This is about as naughty as using the
wrong fork (ie, your typical American has a 50% chance of
doing it right).
only-one-pitchfork-at-my-trough-ly y'rs
- Gordon
More information about the Python-list
mailing list