Ideas regarding flow control and loops

Marco Aurélio thecoreh at gmail.com
Sat Nov 3 18:13:56 PDT 2007


Robert Fraser Wrote:

> 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.

Wow. I didn't know you could do that, even with closures.



More information about the Digitalmars-d mailing list