DrSchool Learn coding, fast.
EN AR BN CS DE EL Search

Recursion — Example 91

Quick explanation + ready code for: Recursion.

Lua Recursion Back to examples
Back to language
Syntax: Recursion in Lua. ID: #91

Code

function fact(n){ return n<=1?1:n*fact(n-1); }
console.log(fact(4));

Notes

You can copy this snippet and adapt it. For advanced, add real-world inputs, edge cases, and tests.