for, foreach identifier allowed in c throws error in d
Logesh Pillay via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jun 2 12:47:02 PDT 2014
Issue has nothing to do with recursion. That's only where I keep
seeing it.
eg a function to generate combinations.
import std.stdio;
int[3] t;
void foo (int i) {
if (i == 3)
writef("%s\n", t);
else foreach (x; 0 .. 3) {
t[i] = x;
foo(i+1);
}
}
void main() {
foo(0);
}
In C, I could put in the equivalent for statement for foreach,
t[i] as the iterating variable. I won't need x which exists as a
middleman only and save myself two lines.
More information about the Digitalmars-d-learn
mailing list