The first version of the
factorial function calls itself with the same value of
n that was passed to it. Therefore, it never resolves the calculation. It is an example of an infinite recursion.
For each call to itself, the second version passes a value to itself that is one less than the value that it was given. For any non-negative value of
n, the recursion eventually resolves to the base case, where
0. When that happens, each invocation of the function can
return a value to the invocation that called it, until all the invocations have completed.