There are two types of recursive functions in programming
. There is direct recursion
, where a function
calls itself from within its own body, and indirect recursion
where a function calls a second function which in turn calls the first function again.
Most programming books will teach recursion by using it to solve problems such as exponential statements and fibonacci numbers. The fact is, these problems usually have simpler solutions than recursion, which is often bulky, slow, hard to read, or first and foremost a memory eater.
Occasionally, however, recursion is the best solution. If you can't solve the problem using loops, try recursion, but be careful.