Re: Instructions in for
- To: mathgroup at smc.vnet.net
- Subject: [mg89400] Re: Instructions in for
- From: David Bailey <dave at Remove_Thisdbailey.co.uk>
- Date: Sun, 8 Jun 2008 02:33:25 -0400 (EDT)
- References: <g2dboa$9pm$1@smc.vnet.net>
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 http://www.dbaileyconsultancy.co.uk