# How can I make 10 variables from a for loop?

I used a for loop to make 4 variables:

   For[i = 0, i < 4, i++,bi=0]


But when I write b0 or b1 it print its as b0 or b1 not 0 or 0.

• possible duplicate: 783
– Kuba
Oct 14, 2022 at 9:57
• An alternative approach is to use Array[a, 10]. Now you have created 10 different a's that you can use as a or a. Oct 14, 2022 at 16:30
• Mathematica is different from explicit programming (C, Python, etc.): in Mathematica there is no need for such explicit assignments. In this case, for example you could define b[i_] = 0 to make every value zero (as a pattern), or you could restrict it to your values with b[i_Integer /; 0 <= i < 4] = 0. Please read an introduction to the Wolfram language. Oct 15, 2022 at 6:44

You might find it easier to do

For[i = 0, i < 4, i++,b[i]=0]

b (* gives 0 *)


You could use ToExpression

For[i = 0, i < 4, i++, ToExpression["b" <> ToString[i] <> "=" <> ToString[i]]]


and now I am not sure why you want to do the above, there could be better ways to solve the problem you are trying to solve if you explain the purpose of doing this.