MathGroup Archive 2007

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

Search the Archive

Re: question about For

  • To: mathgroup at
  • Subject: [mg84140] Re: question about For
  • From: Bill Rowe <readnewsciv at>
  • Date: Tue, 11 Dec 2007 06:10:59 -0500 (EST)

On 12/10/07 at 8:43 PM, amorales at (Ary Adilson Morales
Alvarado) wrote:

>I would like to know how to save the data from a For loop.

>Something like that:

>t=For[i = 1, i < 5, Print[i]; i++]

>t={1, 2, 3, 4}

If you insist on using a For loop, one way to do what you want
would be:

In[4]:= t = {};
For[i = 1, i < 5, t = {t, i}; i++];
t = Flatten@t;

Out[7]= {1,2,3,4}

But, clearly


is much more efficient. And I am certain there will be a more
efficient method to solve whatever your real problem is than
using a For loop. In Mathematica, the For command is very much
like goto in C. It is there and you can use it but there are
better ways.
To reply via email subtract one hundred and four

  • Prev by Date: Re: Inset problems & Export
  • Next by Date: Re: Mathematical expectation
  • Previous by thread: Re: question about For
  • Next by thread: Re: question about For