I have some variables : Subscript[S, 1], Subscript[S, 2]...etc.
But they are defined in a for loop like For[g = 1, g < 4, g++, Subscript[S, g] = g];
Later, I need to print each of the variable name, i.e Subscript[S, 1], Subscript[S, 2]...etc. But I can't find a systematic way to do this. For[g = 1, g < 4, g++, Print[HoldForm@Subscript[S, g]]]; doesn't work because it prints Subscript[S, g] always.
Any idea?
Just look at the code:
For[g = 1, g < 4, g++, Subscript[S, g] = g];
Print[Subscript[S, 1]]
Print[Subscript[S, 2]]
Print[Subscript[S, 3]]
For[g = 1, g < 4, g++, Print[Subscript[S, g]]];
Print[HoldForm@Subscript[S, 1]]
Print[HoldForm@Subscript[S, 2]]
Print[HoldForm@Subscript[S, 3]]
For[g = 1, g < 4, g++, Print[HoldForm@Subscript[S, g]]];
For[g = 1, g < 4, g++, Subscript[S, g] =.];
And this is the result:

Deferand What are the most common pitfalls awaiting new users? – ssch Sep 09 '13 at 13:16Do[..., {g, 3}]instead ofFor[g = 1, g < 4, g++, ...];. It's idiomatic, easier to read and maintain, and possibly faster. OrMap, if possible, or some other construct. – Volker Sep 09 '13 at 13:17Spart:Subscript[S, 3] = 4; g = 3; Subscript[Defer[S], g]– ssch Sep 09 '13 at 13:32