Re: problem with append

• To: mathgroup at smc.vnet.net
• Subject: [mg129546] Re: problem with append
• From: Alexei Boulbitch <Alexei.Boulbitch at iee.lu>
• Date: Tue, 22 Jan 2013 02:39:46 -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

```hello i am new to mathmatica.i have the following problem if anyone could help.

For[a = 2, a < 6, a++,
For[b = 2, b < 6, b++,
Appendto[rr = {}, a^b]]]
rr

but rr remains empty. how can i solve this
thank you

Hi, Paolo,
You have problems with syntax. Instead try this:

Block[{r = {}},
For[a = 2, a < 6, a++, For[b = 2, b < 6, b++, AppendTo[r, a^b]]];
Print[r]
]

{4,8,16,32,9,27,81,243,16,64,256,1024,25,125,625,3125}

Or this:

a = {};
Block[{r = {}},
For[a = 2, a < 6, a++, For[b = 2, b < 6, b++, AppendTo[r, a^b]]];
a = r
]

{4, 8, 16, 32, 9, 27, 81, 243, 16, 64, 256, 1024, 25, 125, 625, 3125}

Take care that it is not "Appendto", but "AppendTo" that is important. However, in Mathematica the utilization of loops is usually discouraged. Use better Table, like this:

Table[i^j, {i, 2, 5}, {j, 2, 5}]

{{4, 8, 16, 32}, {9, 27, 81, 243}, {16, 64, 256, 1024}, {25, 125, 625,
3125}}

Table[i^j, {i, 2, 5}, {j, 2, 5}] // Flatten

{4, 8, 16, 32, 9, 27, 81, 243, 16, 64, 256, 1024, 25, 125, 625, 3125}

Have fun, Alexei

Alexei BOULBITCH, Dr., habil.
IEE S.A.
ZAE Weiergewan,
11, rue Edmond Reuter,
L-5326 Contern, LUXEMBOURG

Office phone :  +352-2454-2566
Office fax:       +352-2454-3566
mobile phone:  +49 151 52 40 66 44

e-mail: alexei.boulbitch at iee.lu

```

• Prev by Date: Re: Solid State Disk to boost Mathematica performance
• Next by Date: Re: Solid State Disk to boost Mathematica performance
• Previous by thread: Re: problem with append
• Next by thread: Re: InterpolatingPolynomial error message