Recursion in AngelScript
Our example demonstrates recursive functions in AngelScript. Here’s a classic implementation of factorial calculation using recursion.
This fact
function calls itself until it reaches the base case of fact(0)
.
In the main
function, we first call and print the result of fact(7)
.
AngelScript also supports recursive closures. We define a function type fibonacci
and then create a closure that calculates Fibonacci numbers recursively.
Note that in AngelScript, we use the funcdef
keyword to define a function type, and the @
symbol to declare a function handle.
The output of this program would be:
This example showcases how recursion can be used both in regular functions and in closures in AngelScript. The factorial function demonstrates simple recursion, while the Fibonacci closure shows a more complex recursive pattern.