[Tutor] Re: My code freezes python. :-)

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Sun Jan 12 01:47:02 2003


> It's not frozen.  It's running, but not doing anything (apparently)
> useful.
>
> |    while times > -1 :
>
> We stop when 'times' is less than or equal to -1.  Presumably 'times'
> is initially a positive number.
>
> |        times=times+1
>
> Here times is incremented.  It gets larger.  Since it started >-1, it
> is now moving farther away.  This loop can never end.

Incidently, this chunk of code might have terminated in a language where
arithmetic can overflow.  In a more hardware-oriented language like C,
numbers are restricted to a certain range, where going beyond that range
makes us jump around to the other side of the range, that is, to
"overflow".

However, since Python has "long ints", overflow doesn't occur on addition:
we'll be able to continue blissfully incrementing till we run out of
virtual memory.  *grin*