Control Structures Proposal

janderson askme at me.com
Tue Jul 24 23:57:01 PDT 2007


downs wrote:
> janderson wrote:
>> For example you can currently do something like this in D (untested).
>>
>> For({int i=0;}, i!=0, {++i})
>> ({
>>
>>
>> });
> 
> You can do better.
> 
> void For(lazy void ini, lazy bool cond, lazy void inc, void delegate() 
> dg) {
>         for (ini(); cond(); inc()) dg();
> }
> 
> import std.stdio;
> void main() {
>   int i=void;
>   For (i=0, i<10, ++i, { writefln(i); });
> }
> 
> Yay for lazy void!
>  --downs


I'm aware of this, I don't think its as close as having the delegate in 
its own block.

-Joel



More information about the Digitalmars-d mailing list