yieldその後

結構、使えるようになってきた?

using System;
using System.Collections.Generic;

class Fib : IEnumerable [int] {
    mutable max = 0;
    public this (n : int) {
        max = n;
    }

    public GetEnumerator () : IEnumerator [int] {
        mutable (a, b) = (0, 1);
        while (b < max) {
            yield b;
            (a, b) = (b, a + b);
        }
    }
}

foreach (n in Fib (20))
    Console.WriteLine (n);

/*
1
1
2
3
5
8
13
 */