Here you can see the chain of returns, and how each fact
call looks. Each time there's an attempt to return, it must evaluate what the value of fact(n - 1)
is before giving back a value. Which is why the second it tries to return 3 * fact(2)
, it evaluates fact(2)
, but fact(2)
will have to evaluate fact(1)
, and fact(1)
will have to evaluate fact(0)
. The second that chain breaks by returning 1, it goes back up each return and will "insert" the result of that fact
call and multiply it. I tried to show this as best I could, the return statements evaluated in parentheses, the result in square brackets [X] and a display to show the chain of where it's inserted/used as the multiplier in the above return.