RosettaCodeData/Task/Fibonacci-sequence/Haxe/fibonacci-sequence-2.haxe

20 lines
342 B
Text
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
class FibIter
{
2016-12-05 22:15:40 +01:00
private var current = 0;
private var nextItem = 1;
2013-04-10 21:29:02 -07:00
private var limit:Int;
2016-12-05 22:15:40 +01:00
public function new(limit) this.limit = limit;
public function hasNext() return limit > 0;
2013-04-10 21:29:02 -07:00
2016-12-05 22:15:40 +01:00
public function next() {
2013-04-10 21:29:02 -07:00
limit--;
var ret = current;
var temp = current + nextItem;
current = nextItem;
nextItem = temp;
return ret;
}
}