Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: problem with append
Replies: 1   Last Post: Jan 21, 2013 12:06 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
svkeeley@aol.com

Posts: 9
Registered: 12/27/12
Re: problem with append
Posted: Jan 21, 2013 12:06 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.