| www.delorie.com/gnu/docs/octave/octave_68.html | search |
![]() Buy GNU books! | |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
With some restrictions(2), recursive function calls are allowed. A recursive function is one which calls itself, either directly or indirectly. For example, here is an inefficient(3) way to compute the factorial of a given integer:
function retval = fact (n)
if (n > 0)
retval = n * fact (n-1);
else
retval = 1;
endif
endfunction
|
This function is recursive because it calls itself directly. It eventually terminates because each time it calls itself, it uses an argument that is one less than was used for the previous call. Once the argument is no longer greater than zero, it does not call itself, and the recursion ends.
The built-in variable max_recursion_depth specifies a limit to
the recursion depth and prevents Octave from recursing infinitely.
The default value is 256.
| webmaster donations bookstore | delorie software privacy |
| Copyright © 2003 by The Free Software Foundation | Updated Jun 2003 |