understanding recursion vs loops
I have the following recursion method. I get an error stack overflow. it
stops at -9352. My questions, is stack overflow the same as an infinite
loop? Because this will keep calling itself.
But if I do a infinite loop with while, until, do, etc it doesn't give me
the same stack overflow error. It just keeps going until my system runs
out of memory.
def recursion(n)
print n
recursion(n-1)
end
recursion(3)
No comments:
Post a Comment