In the last exercise, you created a condition that determines whether or not
findFactorialRecursively() calls itself. We call this
if block the recursive case.
In recursion, the recursive case is the condition under which a function calls itself. We call this the recursive case because, recursion is defined as a process that includes a function calling itself.
At this point, we are still missing a couple of components from our recursive method:
Calculating the product of each number. While the current implementation does access all the numbers that we need to multiply, we do not calculate their product.
0– the value set to
recursiveSolution(see Factorial.swift to the right) is zero, because we always return
We’ll tackle #1 next.
if block, return the product of
n and your call to
After you run your code, you should see that the value saved to
findFactorialRecursively is still
0. Why didn’t it return the values from the product of
n * findFactorialRecursively(n - 1)?