Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

A recursive function is a function which calls itself. It classic example is calculating N factorial.

N factorial is represented using N!

N factorial is calculated by taking N * (N-1) * (N-2) …. (1)

For example 5! is 5 * 4 * 3 * 2 *1.

We can calculate this with Lua like this:

function FACTorial(N)
   if (N == 1) then
      return 1   
   end
   return N * FACTorial(N-1)
end

function main(Data)
    local Result = FACTorial(5);
end

  • No labels