MathGroup Archive 2008

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

Search the Archive

Re: Instructions in for

  • To: mathgroup at
  • Subject: [mg89400] Re: Instructions in for
  • From: David Bailey <dave at>
  • Date: Sun, 8 Jun 2008 02:33:25 -0400 (EDT)
  • References: <g2dboa$9pm$>

Alejandra Lozada 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.
Just provide a number of instructions separated by semicolons. This 
construct is known as a compound instruction:

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

You can put a compound instruction anywhere where an instruction is 
needed, for example:

For[ i=1, i<n, Print["Before increment i=",i];i++, Print[i] ]

I think you would find a course on Mathematica fundamentals very 
beneficial. Alternatively, try to read and experiment with some code 
that others have written.

David Bailey

  • Prev by Date: A question about N[...]
  • Next by Date: Re: Dynamic GUI problems
  • Previous by thread: Re: Instructions in for
  • Next by thread: Re: Options for showing scan delay