repeat/while?

Alex Martelli aleaxit at yahoo.com
Thu May 3 17:56:13 EDT 2001


"Russell Nelson" <nelson at crynwr.com> wrote in message
news:m2snimw86x.fsf at desk.crynwr.com...
> Is there any enthusiasm for repeat/while in Python?  It would replace the
following ideom:
>
> while 1:
>     line = sys.stdin.readline()
>     if not line: break
>     pass  # handle line here
>
> with this:
>
> repeat:
>     line = sys.stdin.readline()
> while line:
>     pass  # handle line here

I think the syntax would be slightly nicer in the repeat/while case, yes,
and even more if it was spelled loop/while.  This tepid reaction is about
as much "enthusiasm" as you're likely to get, I suspect:-).  One plus
is that this would be VASTLY superior to such hacks as "do/until": it
would generalize the syntax of while, by adding an optional loop
clause before the while clause, rather than add another different
statement that only covers a subset of needed loops (like while as
it stands now, but the while loop turns out to be a frequent case).



> Or should I write this up as a PEP?

This would be an excellent idea, I think, since it would eventually lead
to a BDFL pronouncement on this possible syntax tweak.


Alex






More information about the Python-list mailing list