7.19. Recursion

It is sometimes useful for methods to call themselves—a recursive method is a method that calls itself either directly or indirectly (i.e., through another method). In this section, we present a simple example of recursion.

Let us first consider recursion conceptually. Recursive problem-solving approaches have a number of elements in common. A recursive method is called to solve a problem. The method actually knows how to solve only the simplest case(s)—the base case(s). If the method is called with a base case, it returns a result. If the method is called with a more complex problem, it divides the problem into two conceptual pieces—a piece that the method knows how to perform (i.e., base case), and a piece that it does not know ...

Get Visual Basic 2005 for Programmers: Deitel Developer Series, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.