Using Recursive Functions
IN THIS CHAPTER
Defining recursion and how it works
Using recursion to perform advanced tasks
Mixing recursion with functions
Understanding common recursion errors
Some people confuse recursion with a kind of looping. The two are completely different sorts of programming and wouldn’t even look the same if you could view them at a low level. In recursion, a function calls itself repetitively and keeps track of each call through stack entries, rather than an application state, until the condition used to determine the need to make the function call meets some requirement. At this point, the list of stack entries unwinds with the function passing the results of its part of the calculation to the caller until the stack is empty and the initiating function has the required output of the call. Although this sounds mind-numbingly complex, in practice, recursion is an extremely elegant method of solving certain computing problems and may be the only solution in some situations. This chapter introduces you to the basics of recursion using the two target ...