for, foreach identifier allowed in c throws error in d

2014-06-02 Thread Logesh Pillay via Digitalmars-d-learn
It is common in a recursive function to amend a global array using the function parameter to refer to the element eg int[10]; void foo (int i) { foreach (x; 0 .. 9) { t[i] = x; foo (); C in a for loop allows use of t[i] directly as the iterating variable so you don't need the dumm

Re: for, foreach identifier allowed in c throws error in d

2014-06-02 Thread Logesh Pillay via Digitalmars-d-learn
Of course, in the first line I meant to say int[10] t;

Re: for, foreach identifier allowed in c throws error in d

2014-06-02 Thread Logesh Pillay via Digitalmars-d-learn
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); } I

Re: for, foreach identifier allowed in c throws error in d

2014-06-02 Thread Logesh Pillay via Digitalmars-d-learn
Sorry, I am embarassed to say I've just tried the for equivalent and it works with t[i] as the iterating variable. import std.stdio; int[3] t; void foo (int i) { if (i == 3) writef("%s\n", t); else for (t[i] = 0; t[i] < 3; t[i]++) foo(i+1); } void main() { foo(0); } Sorry, yet