MathGroup Archive 2009

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

Search the Archive

Re: For loops with mathematica....

  • To: mathgroup at
  • Subject: [mg101098] Re: [mg101069] For loops with mathematica....
  • From: "David Annetts" <davidannetts at>
  • Date: Wed, 24 Jun 2009 06:30:57 -0400 (EDT)
  • References: <>

Hi Julien,
> I am totally new to mathematica.
> I want to use a simple loop for but with many arguments in the loop...
> the help says to do
> Do[ thingstodo, {i,8}]
> i will go from 1 to 8 to do thingstodo.
> First question: what if I want i to go from 20 then 200 then 
> 300 then 400, (can we give a sequence as argument?)

You can do this.  Try

 {ji, {Range[20], Range[200, 300], 400}}

crange = Join[Range[20], Range[200, 300], {400}];
 {ji, crange}

> Second question: I have a lot of line to do in things to do. 
> should I separate everything with a ; (doesn t seem to work, 
> or use a procedure or something?)

Multiple statements inside a loop have to be separated using ";".

As an example,
 a = Sin[ji Degree];
 b = Cos[ji Degree];
 Print[ji, "\t", a, "\t", b],
 {ji, 0, 90, 45}

As with any programming language, you'll want to put stuff in Module[]'s as
readability diminishes


  • Prev by Date: Re: Ansatz?
  • Next by Date: Re: Matrix construction
  • Previous by thread: For loops with mathematica....
  • Next by thread: Re: For loops with mathematica....