zig/doc/langref/fibonacci_comptime_infinite_recursion.zig

13 lines
247 B
Zig

const assert = @import("std").debug.assert;
fn fibonacci(index: i32) i32 {
//if (index < 2) return index;
return fibonacci(index - 1) + fibonacci(index - 2);
}
test "fibonacci" {
try comptime assert(fibonacci(7) == 13);
}
// syntax