Domino Code Fragment

Code Name*
Factorial of n using recursion
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.144.98.13
Description*
Returns the factorial of a number n using recursion
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
A function that calls itself is known as a recursive function. Each time a recursive function calls itself, an entirely new data area for that particular call must be allocated. Writing a recursive function produces compact code but causes an increase in the use of memory. Each call causes a new data area to be allocated, and each reference to an item in the function's data area is to the data area of the most recent call. Similarly, each return causes the current data area to be freed, and the data area allocated immediately prior to the current area becomes current.
Files/Graphics attachments (if applicable): Code:
Public Function Factorial (n As Integer) As Long
    If n <= 0 Then                
         Factorial = 1
    Elseif n = 1 Then              
         Factorial = 1
    Else
         Factorial = n * Factorial (n - 1)
    End If


   Print Factorial(1)          ' Prints 1
  Print Factorial(2)          ' Prints 2
  Print Factorial(3)          ' Prints
6
End Function