MathGroup Archive 2013

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: problem with append


> 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}



  • Prev by Date: Re: Saving mov in v9
  • Next by Date: Re: problem with append
  • Previous by thread: Re: problem with append
  • Next by thread: Re: problem with append