How Nested Functions Work, part 1

bearophile bearophileHUGS at lycos.com
Wed Sep 2 05:03:52 PDT 2009


If the loop index "i" isn't necessary, you can use simpler code:

import std.stdio: writeln;

void repeat(TF)(int n, lazy TF callme) {
    foreach (i; 0 .. n)
        callme();
}

void main() {
    repeat(5, writeln("hi"));
}

Bye,
bearophile



More information about the Digitalmars-d mailing list