Solutions written recursively are often simple. Recursive solutions are also often much easier to conceive of and code than their iterative counterparts. In general, problems that are defined in terms of themselves are good candidates for recursive techniques. The standard example used by many computer science textbooks is the factorial function. Take a good close look at the above, and you may notice something interesting.
Lets test it to make sure it works.
We messed up. This is a good time to talk about how one should write a recursive function, and what two cases must be considered when using recursive techniques. There are four important criteria to think about when writing a recursive function. The base case, or halting case , of a function is the problem that we know the answer to, that can be solved without any more recursive calls. The base case is what stops the recursion from continuing on forever.