Control Structures Proposal
downs
default_357-line at yahoo.de
Tue Jul 24 23:12:35 PDT 2007
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
More information about the Digitalmars-d
mailing list