6.21. Recursion vs. Iteration

This section compares the recursive and iterative problem-solving approaches and discusses why you might choose one over the other in a particular situation.

• Both iteration and recursion are based on a control statement: Iteration uses a repetition structure; recursion uses a selection structure.

• Both iteration and recursion involve repetition: Iteration explicitly uses a repetition structure; recursion achieves repetition through repeated function calls.

• Iteration and recursion each involve a termination test: Iteration terminates when the loop-continuation condition fails; recursion terminates when a base case is recognized.

• Iteration with counter-controlled repetition and recursion each gradually approach ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

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