Python loop constructs

John Roth johnroth at ameritech.net
Wed Jan 15 14:36:44 CET 2003


"Jonathan P." <jbperez808 at yahoo.com> wrote in message
news:f57664b9.0301142008.6a0888 at posting.google.com...
> In a couple of old threads, "LOOP wisdom found"
> and "do...until wisdom found", someone mentioned
> that a construct of the type:
>
> loop:
>   do-stuff
>   if condition: leave
>
> is the cleanest possible solution and that we
> can expect to see something like it for "Python 3K".
> But doesn't the present 'while' syntax already give
> you all that and more?
>
> while 1:
>   do-stuff
>   if condition: break
>
> while condition:
>   do-stuff
>
> If one thinks of while 1: as an alias for loop: then
> I don't find anything objectionable to its usage at all.
> In addition:
>
>   while (condition): do-stuff
>
> would be a lot clearer than:
>
>   loop (condition): do-stuff
>
> or
>
>   loop while (condition): do-stuff # YUCK!

The objection that people have to

while 1:

or

while True: (as in Python 2.3)

is that it's an idiom and they'd like it to be
more clearly stated. Frankly, I can't get myself
all that fired up over the issue when there are
lots of larger issues to work on.

John Roth






More information about the Python-list mailing list