Re: Assignment problem

*To*: mathgroup at smc.vnet.net*Subject*: [mg86259] Re: Assignment problem*From*: "jwmerrill at gmail.com" <jwmerrill at gmail.com>*Date*: Fri, 7 Mar 2008 02:26:59 -0500 (EST)*References*: <fqo8o1$suo$1@smc.vnet.net>

On Mar 6, 3:07 am, Marco Gabiccini <m.gabicc... at ing.unipi.it> wrote: > Hi all, > > I would like to do something like: > > For[ i=1, i<n, i++, ToExpression[ "q" <> ToString[i] ] = 0 ] > > that is assigning q1=0, q2=0, etc... but it does not work. Just need to through in an Evaluate in the right place (this seems to be the solution to a lot of problems in Mathematica). For[i = 1, i < n, i++, Evaluate[ToExpression["q" <> ToString[i]]] = 0] Do (or Table if you want to see what you've just assigned) would be a little cleaner here. Along with a couple other functions like Map and Nest, these can almost always be used to rewrite a For expression more cleanly. Do[Evaluate[ToExpression["q" <> ToString[i]]] = 0, {i, n-1}] Good Luck, JM