-
Book Overview & Buying
-
Table Of Contents
Linux Command Line and Shell Scripting Bible - Third Edition
By :
One feature that local function variables provide is self-containment. A self-contained function doesn't use any resources outside of the function, other than whatever variables the script passes to it in the command line.
This feature enables the function to be called recursively, which means that the function calls itself to reach an answer. Usually, a recursive function has a base value that it eventually iterates down to. Many advanced mathematical algorithms use recursion to reduce a complex equation down one level repeatedly, until they get to the level defined by the base value.
The classic example of a recursive algorithm is calculating factorials. A factorial of a number is the value of the preceding numbers multiplied with the number. Thus, to find the factorial of 5, you'd perform the following equation:
5! = 1 * 2 * 3 * 4 * 5 = 120
Using recursion, the equation is reduced down to the following format:
x! = x * (x-1)!
or in English, the factorial...
Change the font size
Change margin width
Change background colour