Python loop constructs

Jonathan P. jbperez808 at yahoo.com
Wed Jan 15 05:08:04 CET 2003


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!




More information about the Python-list mailing list