delegete with foreach

%u not at possible.de
Thu Jan 11 07:31:33 PST 2007


Hello,

i try to understand this programm.

import std.stdio;

void main()
{
        auto dg = delegate (int delegate( inout int) dgp)
        {
                static int j=0;
                int res=0;
                while( j < 5){
                        j++;
                        res= dgp(j);
                        if(res) break;
                }
                return res;
        };

        foreach (int i; dg)
        {
                writefln(i);
        }

}

Output:
1
2
3
4
5

Is this a function with a return value
and with one delegate parameter ?
auto dg = delegate (int delegate( inout int) dgp)
{
.
.
.
     return res;
}

If this a function, what name have the function?

Thanks


More information about the Digitalmars-d-learn mailing list