PEP-315 ("do" loop)

Raymond Hettinger python at rcn.com
Tue Feb 17 02:13:22 EST 2004


[Wayne Folta]
> Two observations about PEP-315:
. . .
 
> In a neater way? How about, instead, creating an "until" loop:
> 
> until line == "\n":
>      line = sys.stdin.readline()
> 
> Would be defined to work exactly like a while loop except the test is 
> not evaluated the first time through the loop. Wouldn't this be akin to 
> checking at the end of the loop, while maintaining a more while-ish 
> syntax?

While it works, or should I say "until it doesn't work", there are two
issues.  First, this is not the usual meaning of "until" in other
languages where the semantics is like "while" with the condition
inverted.  Second, it is much more clear to put the condition at the
point in the program that it gets evaluated (at the end of the loop,
not the beginning).


Raymond Hettinger



More information about the Python-list mailing list