Geoff Canyon wrote:

> At 1:59 PM +1200 8/8/01, Rodney Tamblyn wrote:
>> Instead of:
>> 
>> repeat with x = 1 to the number of items in myVar
>> 
>> ... could have:
>> 
>> repeat with x in myVar by <delimiter>
>> 
>> Advantages:
>> - simpler syntax
>> - consistent with syntax of other new commands in 2.4 like split
>> 
>> Delimiters could be  comma|word|return
> 
> Sure, you can have that:
> 
> --comma, assuming you haven't set the itemDelimiter property
> repeat for each item i in 1,2,3
> 
> --word
> repeat for each word i in "MC Rocks Big Time"
> 
> --return
> repeat for each line i in "Just one line, but you get the idea."

And boy oh boy! is the "repeat for each" so much faster than "repeat with".

"Repeat for each" parses the chunks for you and keeps its pointer into the
parsed data, as opposed to "repeat with", which counts through the data from
0 to i in each iteration.

And if you need a counter in the loop, I've found it's usually much faster
to keep your own counter in a "repeat for each" loop, even with the minor
additional overhead.

For example, this:

   put 0 into tCounter
   repeat for each line tLine in tData
      add 1 to tCounter
      put "processing line "&tCounter
      DoSomethingWith tLine
   end repeat

is faster than:

   repeat with i = 1 to the number of lines of tData
       put "processing line "&i
       DoSomethingWith line i of tData
   end repeat


You can run your own comparative tests to see the benefits yourself using
MetaBench: 
<ftp://ftp.fourthworld.com/MetaCard/4W_MetaBench.mc.sit.hqx>

 
-- 
 Richard Gaskin 
 Fourth World Media Corporation
 Multimedia Design and Development for Mac, Windows, UNIX, and the Web
 _____________________________________________________________________
 [EMAIL PROTECTED]                 http://www.FourthWorld.com
 Tel: 323-225-3717           ICQ#60248349            Fax: 323-225-0716



Archives: http://www.mail-archive.com/[email protected]/
Info: http://www.xworlds.com/metacard/mailinglist.htm
Please send bug reports to <[EMAIL PROTECTED]>, not this list.

Reply via email to