Below, is a program that recurses a number of times. To keep the computer from running out of memory , the number of iterations has been limited by using a while loop to make the recursive call. After a certain number of instances the recursive call ends, and all of the function calls exit, and program flow returns to the main body of the program . This kind of behavior is the key to recursion. If you can develop a fundamental grasp of the fact that each instance of the function call is a separate entity, you can use it to make programs that do some very useful and amazing things.
Recursion brings a mixed blessing.
It can make simple work of otherwise complex and enormously iterative tasks. It can also be a nightmare that brings the system to its knees by hogging huge amounts of memory. Debugging recursive routines can be maddeningly difficult. It can take great patience and skill to have success fixing broken recursive code. In fact, it's often easier to rewrite a recursive function than it is to patch in changes.