Max Samuha wrote: > What am I doing wrong? Semms you mean something like this: import std.stdio; void main() { auto dg = delegate (int delegate( inout int) dgp) { static int j=0; int res=0; while( j < 15){ j++; res= dgp(j); if(res) break; } return res; }; foreach (int i; dg) { writefln(i); } }