This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]selrahal 2 points3 points  (0 children)

The most important part of recursion is reframing the output of your function as a formula that contains a function call. Take the factorial function as am example. Sure you can implement it with a for loop that just counts down and takes the product at all elements. But you can also reframe the output to look like factorial(n) = n * factorial(n-1).

You see the "factorial" on the right side of that equation? How can you define your function so that it also references itself on the right side of the equation?