doll recursive function

Code

1

a) function doll(10) gets pushed onto the stack.
b) evaluates that 10 != 0
c) outputs 10
d) calls recursive function doll(10-1). Thus doll(9) gets pushed onto the stack.

3

WE keep going in the same manner until we hit to doll(1)
a) we push doll(1)
b) evaluates that 1!=0
c) prints 1
d) calls recursive function doll(1-1)
e) doll(0) gets pushed onto the stack
f) evaluates that 0==0
g) thus prints “reached 0”
h) execution runs to end, pops doll(0)

4

a) doll(0) pops from the return. Remember, a function pops whenever we hit the end of code, or returns.
b) We then arrive at where we left off at the recursive call in doll(1).
c) we come to end of function in doll(1), so we pop doll(1).

2

We continue popping in the same manner until we get to doll(8-1)…

a) execution runs to end of doll(8), we pop doll(8)
b) we continue where we left off at doll(9-1)
c) we run to end of function for doll(9), we pop doll(9)
d) we continue where we left off at doll (10-1)
e) we run to end of function at doll(10), we pop doll(10)