PEP-315 ("do" loop)
Paul Rubin
http
Tue Feb 17 14:36:49 EST 2004
"John Roth" <newsgroups at jhrothjr.com> writes:
> 2. It is a very general construct, which might be what is called for. But I
> wonder if most of the time it would be used to accomplish something like:
>
> while 1:
> line = sys.stdin.readline()
> if line == "\n":
> break
>
> In a neater way? How about, instead, creating an "until" loop:
>
> until line == "\n":
> line = sys.stdin.readline()
Most other languages have a way to put the test at the bottom of the loop.
Pythonically that could look like:
repeat:
line = sys.stdin.readline()
until: line == '\n'
That would have similar indentation characteristics to try...finally.
More information about the Python-list
mailing list