Functions Defined Recursively Example

Functions can be defined recursively, meaning they can be defined to call themselves.

ASSIGN/FACTORIAL=FUNCTION((X),IF(X<=1,1,X*FACTORIAL(X-1))
Creates a function called factorial that takes one parameter. If the parameter is less than or equal to 1 it evaluates to 1, otherwise it evaluates to X multiplied by the FACTORIAL of X-1.

ASSIGN/V4=FACTORIAL(5)
Assigns V4 the value of 120 (5*4*3*2*1).