5.5 Recursion

Recursion is a devious construction which allows a function to call itself. Here is a simple example:

function y=twoexp(n)

% y=twoexp(n). This is a recursive program
% for computing y=2^n. the program halts
% only if n is a nonnegative integer.

if n==0,
   y=1;
else
   y=2*twoexp(n-1);
end


Next Section: 5.6 Misc.


Created by F.G. Garvan (fgarvan@ufl.edu) on Wed, Oct 01, 97
Last update made Thu Oct 2 11:22:25 EDT 1997.
Back to 5.3 For Loops
Back to Table of Contents
EMAIL: fgarvan@ufl.edu fgarvan@ufl.edu