Re: problem with append

*To*: mathgroup at smc.vnet.net*Subject*: [mg129529] Re: problem with append*From*: svkeeley at aol.com*Date*: Mon, 21 Jan 2013 00:06:42 -0500 (EST)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com*Delivered-to*: l-mathgroup@wolfram.com*Delivered-to*: mathgroup-newout@smc.vnet.net*Delivered-to*: mathgroup-newsend@smc.vnet.net*References*: <kdg2kv$hf8$1@smc.vnet.net>

> For[a = 2, a < 6, a++, > > For[b = 2, b < 6, b++, > > Appendto[rr = {}, a^b]]] > > rr One thing wrong is that everytime through the loop, you reset rr to an empty set. The AppendTo statement should read "Appendto[rr, a^b]" with rr assigned to {} before the loop. This works: rr = {}; For[a = 2, a < 6, a++, For[b = 2, b < 6, b++, AppendTo[rr, a^b]]]; rr {4,8,16,32,9,27,81,243,16,64,256,1024,25,125,625,3125} In[9]:= rr = {}; So does this: rr = {}; For[a = 2, a < 6, a++, For[b = 2, b < 6, b++, rr = Append[rr, a^b]]]; rr {4,8,16,32,9,27,81,243,16,64,256,1024,25,125,625,3125}