I want to print
A[0, 0, 1], A[0, 0, 2], A[1, 1, 1], A[1, 1, 2], A[2, 2, 1], A[2, 2, 2]
using the following code.
For[t = 0, t < 3, t = t + 1,
For[z = 0, z < 3, z = z + 1,
For[i = 1, i < 3, i++, Print[A[t, z, i]]]]]
I want to print
A[0, 0, 1], A[0, 0, 2], A[1, 1, 1], A[1, 1, 2], A[2, 2, 1], A[2, 2, 2]
using the following code.
For[t = 0, t < 3, t = t + 1,
For[z = 0, z < 3, z = z + 1,
For[i = 1, i < 3, i++, Print[A[t, z, i]]]]]
Why exactly you need a loop if you don't want to loop is completely beyond my understanding, but maybe you have processor time to kill or something like that.. Anyway
For[t = 0, t < 3, t++,
For[z = 0, z < 7, z++,
For[i = 1, i < 3, i++,
If[t == z,
Print[A[t, z, i]
]
]
]
]
]
(*
A[0,0,1]
A[0,0,2]
A[1,1,1]
A[1,1,2]
A[2,2,1]
A[2,2,2]
*)
Array[A[#, #, #2] &, {3, 2}, {0, 1}, Flatten[{##},1]&]
Flatten @ Table[A[i, i, j], {i, 0, 2}, {j, 1, 2}]
both give
{A[0, 0, 1], A[0, 0, 2], A[1, 1, 1], A[1, 1, 2], A[2, 2, 1], A[2, 2, 2]}
By pushing the If
up into the 2nd loop, this code wastes a little less processor time than Harlirutan's solution.
For[t = 0, t < 3, t++,
For[z = 0, z < 3, z++,
If[z == t, For[i = 1, i < 3, i++, Print[A[t, z, i]]]]]]