Ideas regarding flow control and loops
Robert Fraser
fraserofthenight at gmail.com
Sat Nov 3 17:45:00 PDT 2007
downs Wrote:
> PS:
> module test17;
> import std.stdio;
>
> void extwhile(lazy bool cond, void delegate() Body, void delegate()
> Finally, void delegate() Else) {
> if (!cond()) Else();
> else {
> do Body(); while (cond());
> Finally();
> }
> }
>
> void main() {
> bool colliding=true;
> int counter=0;
> extwhile(colliding,
> { writefln("Still colliding"); counter++; if (counter==3)
> colliding=false; },
> { writefln("Done colliding"); },
> { writefln("Never collided"); }
> );
> }
Heh, closures are already spreading their intoxicating power.
More information about the Digitalmars-d
mailing list