I understand that
----
import std.stdio;
void main(){
        int delegate() func;
        foreach(i;0..10){
                if(i==5){
                        func= () => i;
                }
        }
        writeln(func());//9
}
----
captures the loop variable,but why does
----
import std.stdio;

void main(){
        int delegate() func;
        foreach(i;0..10){
                auto copy=i;
                if(i==5){
                        func= () => copy;
                }
        }
        writeln(func());//should be 5
}

----
still print 9.

Reply via email to