MathGroup Archive 2007

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

Search the Archive

Re: question about For

  • To: mathgroup at smc.vnet.net
  • Subject: [mg84153] Re: [mg84119] question about For
  • From: János <janos.lobb at yale.edu>
  • Date: Tue, 11 Dec 2007 15:33:00 -0500 (EST)
  • References: <200712110143.UAA18458@smc.vnet.net>

On Dec 10, 2007, at 8:43 PM, Ary Adilson Morales Alvarado wrote:

> Dear friends,
>
> 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}
>
> Thanks in advance
>
> Ary
>
>

Here is a newbie approach:

In[3]:=
t = First[Last[Reap[
      For[i = 1, i < 5,
       Print[i]; Sow[i];
        i++]]]]
 From In[3]:=
1
 From In[3]:=
2
 From In[3]:=
3
 From In[3]:=
4
Out[3]=
{1, 2, 3, 4}

In[4]:=
t
Out[4]=
{1, 2, 3, 4}

J=E1nos



  • References:
  • Prev by Date: Re: Prefix Forms on the BasicMath Palette
  • Next by Date: Re: Vertical tick labels in BarChart
  • Previous by thread: question about For
  • Next by thread: Re: question about For