RosettaCodeData/Task/Fibonacci-sequence/Rhovas/fibonacci-sequence-1.rhovas

12 lines
266 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
func fibonacci(num: Integer): Integer {
require num >= 0;
var previous = 1;
var current = 0;
for (val _ in range(1, num, :incl)) {
val next = current + previous;
previous = current;
current = next;
}
return current;
}