Description: | Being able to completely encapsulate the body of a function by keeping variable changes local to
the function and invisible to the caller we are now able to call a function recursively making
sure each level of recursion works with its own set of variables even thought variable names are
being reused.
Example: The next example below shows how to calculate a Fibonacci number recursively. The recursion stops when the Fibonacci algorism reaches a number greater or equal to a given input number. The example starts with the numbers 0 and 1 the :myFibo function calls itself recursively to calculate the next Fibonacci number until it finds the Fibonacci number greater or equal 1000000000. The first argument of the myFibo function is the name of the variable to store the output in. This variable must be initialized to the Fibonacci number to start with and will be used as current Fibonacci number when calling the function and will be set to the subsequent Fibonacci number when the function returns. |
||
Script: | Download: BatchTutoFuncRecurs.bat
|
||
Script Output: |
|