We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Category: Recursion
Description: Declaring a simple recursive function
Code:
def SampleRec1() { def fib(n) { if (n < 2) 1 else fib(n - 1) + fib(n - 2) } foreach (i in $[0..10]) WriteLine($"fib $i = {0}", fib(i)) } SampleRec1()
Execution Result:
fib 1 = 1 fib 2 = 2 fib 3 = 3 fib 4 = 5 fib 5 = 8 fib 6 = 13 fib 7 = 21 fib 8 = 34 fib 9 = 55 fib 10 = 89
[Copyright ©](Terms of use, legal notice)