Introduction to recursion
Recursion is when a function calls itself. Unlike a loop, recursive calls work inside each other — each waiting for the deeper call to finish before continuing.
Factorial
The factorial of is defined as , with the base case .
Notice the pattern: to compute you only need — then multiply by . To compute you need , and so on, until you reach which is just 1. This is exactly how recursion works.