Chapter 8

Using Recursive Functions

IN THIS CHAPTER

Check Defining recursion and how it works

Check Using recursion to perform advanced tasks

Check Mixing recursion with functions

Check 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 ...

Get Functional Programming For Dummies now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.