Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

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

Search the Archive

Re: question about For

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

On 12/10/07 at 8:43 PM, amorales at lme.usp.br (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;
t

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

But, clearly

t=Range[4]

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