A recursion becomes a loop.
transcript
A recursion can often become a loop. The answer stays the same. The frames disappear. Here is how, in three moves.
Recursion adds one on the way back. A loop adds one on the way forward. Recursion keeps a frame for each comment. The loop keeps two variables.
The recursive call is the last real step. Nothing is left to do after it returns. So no frame needs to wait. This is called a tail call.
The base case becomes the loop test. The recursive call becomes a step forward. The total moves into a variable.
Run the same tests on both versions. The answers must match on every input. Check an empty chain and a long chain. Then ship the loop for deep chains.
A chain of ten thousand comments. The recursion needs ten thousand frames. The loop needs one.
Same logic, same base case, one frame. Full breakdown in the lecture.