Control Structures Proposal

janderson askme at me.com
Wed Jul 25 09:45:51 PDT 2007


downs wrote:
> janderson wrote:
>> 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
> I actually agree with you; I also want some way to do custom blocks. All 
> I'm saying is the existing way isn't entirely as bad as you described 
> it. :p
>  --downs

Thats cool.  Note that I was commenting on using ({ }) which I think is 
better then , {} )  but its a matter of preference I guess.

-Joel



More information about the Digitalmars-d mailing list