12.5 Recursive functions

Hollywood supports recursive functions, i.e. you can write functions which call themselves. For example, here is a function which calculates the faculty of n:

 
Function p_Fac(n)
    If n = 0 Then Return(1)   ; 0! = 1
    Return(n * p_Fac(n - 1))  ; multiply n with n - 1 until n = 0
EndFunction

As you can see above, the p_Fac() function calls itself again and again until the n counter is zero. This is what we call a recursive function.


Show TOC