PEP-315 ("do" loop)
Josiah Carlson
jcarlson at nospam.uci.edu
Wed Feb 18 14:11:11 EST 2004
> 1. It's clever, addresses a definite "wart", and is syntactically
> similar to try/except. But it's syntax seems like an acquired taste to me.
Clever, perhaps. Ugly and confusing, yes. Solves a 'problem' that
isn't a problem, most definitely.
> while 1:
> line = sys.stdin.readline()
> if line == "\n":
> break
I use these all the time, and find them conceptually convenient. Most
Junior/Senior undergraduate computer science majors have no problems
understanding this concept, so I don't think it is necessary to change
the while syntax.
> 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?
As others have said, it is not obvious that until implies "don't test
the condition the first time through".
> Is this at all useful or is something of the order of PEP-315 the way to
> go?
Personally, I find altering the syntax of while, or adding the 'do' to
be a wart. I've never had problems understanding or writing code like
the following;
while 1:
#setup
if <condition>: break
#body
If I had a vote, I'd be -1 on PEP 315.
- Josiah
More information about the Python-list
mailing list