infinite loop

Mike Meyer mwm at mired.org
Tue Sep 6 23:05:39 EDT 2005


"LOPEZ GARCIA DE LOMANA, ADRIAN" <alopez at imim.es> writes:

> Hi all, 
>
> I have a question with some code I'm writting:
>
>
> def main():
>     if option == 1:
>         function_a()
>     elif option == 2:
>         function_b()
>     else:
>         raise 'option has to be either 1 or 2'
>     if iteration == True:
>         main()
[...]
> I want an infinite loop, but after some iterations (996) it breaks:

Since no one else mentioend it: this is only iteration in languages
which mandate tail recursion elimination. Languages that don't do that
are free to do the recursion, which will eventually run you out of
stack. Python is in the latter category, and that's what you ran into.

Thinking about iteration this way is elegant - but it doesn't work
everywhere. Sorry.

            <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list