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

MathGroup Archive 2008

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

Search the Archive

Re: Assignment problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg86365] Re: Assignment problem
  • From: Bill Rowe <readnewsciv at sbcglobal.net>
  • Date: Sun, 9 Mar 2008 05:05:07 -0500 (EST)

On 3/8/08 at 5:42 AM, read at math.uvm.edu (Helen Read) wrote:

>Albert Retey wrote:

>>Note that usually using a Do-Loop is the better choice in
>>Mathematica:

>(as compared with a For loop).

>This is the second post I've seen today that says that Do loops are
>better than For loops in Mathematica. What is better about them
>(aside from slightly simpler syntax)?

Do loops tend to be faster than For loops, For example,

In[39]:= Timing[
 For[sum = n = 0, n < 100000, n++, sum += RandomReal[]]]
sum

Out[39]= {1.09289,Null}

Out[40]= 49920.7

In[41]:= sum = 0;
Timing[Do[sum += RandomReal[], {100000}]]
sum

Out[42]= {0.610351,Null}

Out[43]= 49970.9

--
To reply via email subtract one hundred and four


  • Prev by Date: Re: Another Mathematica 6 bug?
  • Next by Date: Create pdf document from graphics
  • Previous by thread: Re: Re: Assignment problem
  • Next by thread: Re: Assignment problem