# When to use indexed variables

Still learning the fundamentals of the language I would like to ask you what advantages there might be in writing something like:

a = 2;
a = 4;
a = "x";


It seems to me that it is always better to write

a = {2, 4, "x"};


Do you know about any practical constructs where indexed variables would offer an advantage?

• Check this out, particularly the part on sparse arrays – Rojo May 26 '14 at 19:10
• @Rojo I am getting old – Nasser May 26 '14 at 19:36
• ... and I am already reading it, and thank both of you :) – eldo May 26 '14 at 19:37
• Indexed variables can be used symbolically. You can Solve[a^2==2, a] but you can't Solve[a[]^2==2, a[] ]. This is what we typically use when we don't know the number of symbolic variables we need beforehand. I would sometimes define a 3 by 3 matrix with explicit symbolic elements as Array[a, {3,3}]. – Szabolcs May 26 '14 at 19:55
• @Szabolcs - magic ! answer just arrived :) – eldo May 26 '14 at 22:00

vars = Array[a, 3]