while true: !!!

Steve Lamb grey at despair.rpglink.com
Mon Dec 18 19:51:49 CET 2000

On Mon, 18 Dec 2000 07:38:52 -0700, Bjorn Pettersen <pbjorn at uswest.net> wrote:
The most common reason for using "while 1:" (at least in newspostings ;-) is
>because saying what you _really_ mean <0.5 wink>:

>   for line in f.readlines():
>      ...


>has the potential of crashing your machine with an out-of-memory error if you
>don't know the sizes of files you're operating on. 

    ...wastes memory.

>So, the status quo is that because the straight-forward way of doing it is
>too slow, we're all using an optimized idiom that while easy to understand if
>coming from a CS background, doesn't model what you're doing (at least not
>until you've programmed enough Python that reading a file seems like an
>endless loop <wink>).

    Or doing it in the 2-3 other languages I know of which use while in the
exact same manner.  I'm sure if we took a pole of the computer languages known
here you'd find that it is pretty much a standard across many languages, not
just Python.

    Hell, if you want to grouse about readability in Python, why not attack
some of the more obvious targets?  

while (x < 10):
  x = x + 1
  print "What the hell does an else mean on a while loop?"
for x in y:
  print "And here it is on for.  How do you else a loop?  Let's try this."
while 1:
  if (some.condition):
  print "So, is this executed when the loop completes, or when it breaks?"
  print "Which is more obvious to you?  If-else suggests the negative of the"
  print "if statement.  What's the negative of a loop, completion or the"
  print "break?  The answer lies in the same place that while 1: becomes"
  print "quite obvious, the documentation."

         Steve C. Lamb         | I'm your priest, I'm your shrink, I'm your
         ICQ: 5107343          | main connection to the switchboard of souls.

More information about the Python-list mailing list