Is inifinite loop not a good practice?

Terry Reedy tjreedy at udel.edu
Mon Feb 20 16:41:05 EST 2006


"Alvin A. Delagon" <adelagon at gmail.com> wrote in message 
news:43F9DF68.5020301 at gmail.com...
> I've been hearing comments that infinite loop is a bad programming
> practice.

What is bad is an *unintended* loop that goobles cpu time while outputting 
nothing.  Example:

def fact(n):
  res = 1
  while n != 0:
    res *= n
    n -= 1
  return res

fact(-1)

Now imagine that you are paying $360/hr ($.10/sec) (for IBM mainframe time) 
and you should understand the bad reputation (and why jobs were submitted 
with a time limit!). ;-)

Terry Jan Reedy






More information about the Python-list mailing list