Can someone explain the output in this recursion function?

I don't understand why the times variable increases for the return messages.

Once it gets set to 0, shouldn't the function just stop calling itself? What is making time increase back to it's original value?

Picture of the code and output: http://imgur.com/a/Uxre4
I don't understand why the times variable increases for the return messages.

It doesn't. Each function invocation gets it's own copy of a value named times.


Once it gets set to 0, shouldn't the function just stop calling itself?

It does. However, it does not stop executing at that point, and previous invocations waiting for the current invocation to return also do not stop executing until they return.


What is making time increase back to it's original value?

Again, times is not increasing. times is a separate variable for each function invocation. When one invocation returns to a previous invocation, the previous invocation's copy of times is used.


Picture of the code and output:

In the future, please don't link to pictures of code. Post the actual code.
Last edited on
Topic archived. No new replies allowed.