Next topic | Ada Home Page | Index

Recursion

Recursion means writing procedures and functions which call themselves.

Recursion involves:

Eventually a "trivial" problem is reached that can be solved immediately.

Initially it may seem that the solution is incomplete.

General algorithm:

	if stopping condition then
		solve simple problem
	else
		use recursion to solve smaller problem(s)
		combine solutions from smaller problem(s)

Iterative vs Recursive

Recursion is a way of implementing a loop.

Iteration and recursion can always be interchanged.

iteration

recursion


Examples

The best way to understand recursion is to look at lots of examples:


Next topic | Ada Home Page | Index
c-lokan@adfa.oz.au / 23 Feb 96