Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.


Rex
Posts:
23
Registered:
10/13/10


How to do variable number of nesting loops?
Posted:
Jan 14, 2012 11:13 PM


Considering an array a[i], i=0,1,2,...,g, where g could be any given number, and a[0]=1.
for a[1]=a[0]+1 to 1 do for a[2]=a[1]+1 to 3 do for a[3]=a[2]+1 to 5 do ...... for a[g]=a[g1]+1 to 2g1 do ###some computations here###
The problem is that everytime we change the value of g, we need to modify the code, those loops above. So this is not a good code.
Any advice would be greatly appreciated. Languages such as Mathematica, Matlab, Maple, C/C++, or Fortran is fine.



