In the previous exercise, we used an iterative function to implement how a call stack accumulates execution contexts during recursive function calls.
We’ll now address the conclusion of this function, where the separate values stored in the call stack are accumulated into a single return value.
This is the point in a recursive function when we would begin returning values as the function calls are “popped” off the call stack.
We’ll use another
while loop to simulate this process. Write the
while loop below the “Base Case Reached”
This loop will run as long as there are execution contexts stored in
Inside this second loop:
call_stackotherwise you’ll have an infinite loop!
call_stack to see how the execution contexts are removed from
Print that you’re adding
result and their respective values.
Finish the loop by retrieving
return_value and add it to