20 lines
342 B
Plaintext
20 lines
342 B
Plaintext
class FibIter
|
|
{
|
|
private var current = 0;
|
|
private var nextItem = 1;
|
|
private var limit:Int;
|
|
|
|
public function new(limit) this.limit = limit;
|
|
|
|
public function hasNext() return limit > 0;
|
|
|
|
public function next() {
|
|
limit--;
|
|
var ret = current;
|
|
var temp = current + nextItem;
|
|
current = nextItem;
|
|
nextItem = temp;
|
|
return ret;
|
|
}
|
|
}
|