Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: Instructions in for

  • To: mathgroup at smc.vnet.net
  • Subject: [mg89381] Re: Instructions in for
  • From: sigmundv at gmail.com
  • Date: Sun, 8 Jun 2008 02:29:50 -0400 (EDT)
  • References: <g2dboa$9pm$1@smc.vnet.net>

Hello,

You separate the "instructions" by semicolons, e.g.

For[ i=1, i<n, i++, x=i^2; Print[x] ].

However, the use of For in Mathematica must be discouraged, unless no
other solution is at hand (it ought to be seen as the last resort,
since it makes Mathematica programs very slow). In the above example,
a better solution is to use Table:

Table[ i^2, {i,n} ].

/Sigmund


On Jun 7, 9:01 am, "Alejandra Lozada" <alo... at gmail.com> wrote:
> Hello Group,
>
> ______________________________________________
> QUESTION: how to introduce many instructions in for?
> ______________________________________________
>
> In C++ it is possible to use while/for and
> include many instructions:
>
> for( i=0; i<n; i++ ){
>     instructions,
>     as many as you
>     like }
>
> In Mathematica, one instruction (Print)  :
>
> For[ i=1, i<n, i++, Print[i] ]
> how can I include more instructions?
>
> Thank you All,
> Alejandra L.



  • Prev by Date: ListAnimate or movie with No AppearanceElements
  • Next by Date: Re: Instructions in for
  • Previous by thread: Re: Instructions in for
  • Next by thread: Re: Instructions in for