Repetition Through Iteration
Iteration is a type of repetition that, like recursion, involves repeating a task a certain number of times, or for every element in a list, or more generally until some condition is met. Iterative functions provide a means of carrying out these commonly performed tasks without having to explicitly create recursive functions. In general, any linear recursive function (a function with a single recursive call in each of its recursive cases) can be written using an iterative function. Most of the examples in this chapter are iterative versions of the functions written using recursion in Chapter 6. You should compare the iterative solutions to their recursive counterparts and decide which seems more natural to you.
KeywordsOuter Loop Nest Loop Recursive Call Company List Infinite Loop
Unable to display preview. Download preview PDF.