Ideas regarding flow control and loops
downs
default_357-line at yahoo.de
Sat Nov 3 19:47:02 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.
It doesn't actually use closures. Completely D 1.0 :)
Those { } things are short-hand for () { }, i.e. completely normal
delegate literals.
--downs
More information about the Digitalmars-d
mailing list