In article <[EMAIL PROTECTED]>,
 "Terry Reedy" <[EMAIL PROTECTED]> wrote:

> "Alvin A. Delagon" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> > 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

Could be worse.  You could have written:

def fact(n):
   if n == 0:
      return 1
   else:
     return n * fact (n-1)

then you would have not only gotten zonked on CPU charges, but on memory 
charges as well :-)
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to