Recursivity
ufLang supports recursivity:
Explanation:
Recursive function (
factorial
):The function takes an integer
n
and returns the factorial ofn
.If
n
is0
, it returns1
(base case).Otherwise, it calls itself with
n - 1
and multiplies the result byn
(recursive step).
Main function:
We set a number (
5
in this case) and calculate its factorial by calling thefactorial
function.Finally, it prints the result, which will be
120
(i.e., 5 * 4 * 3 * 2 * 1).
Last updated