Basically there are two possibilities.
I you can replace your For - by Do- Loops this should work ( x ist the number of loops put into each other). Of course you could construct index with different end-points
x = 3;
index = Table[{i[j], 1, 2}, {j, 1, x}]
Do[
Print[i[1], i[2], i[3]],
Evaluate[Sequence @@ index]]
Or you could use
Lm = 3; (* number of loops *)
j = {2, 4, 3}; (* end-points *)
Clear[test]
test := Module[{},
L = L + 1;
If[L == 1 && a[[L]] == j[[L]], Return["end"]];
If[L == Lm,
If[a[[L]] == j[[L]],
a[[L]] = 0;
L = L - 2;
test,
a[[L]] = a[[L]] + 1;
Print[a];
nc = nc + 1; e1[[nc]] = a;
L = L - 1;
test
],
If[a[[L]] == j[[L]],
a[[L]] = 0;
L = L - 2;
test,
a[[L]] = a[[L]] + 1;
test
]
]
]
Now
L = nc = 0;
a = Table[0, {Lm}];
e1 = Table[0, {Times @@ j}];
test