It is absolutely faster. It was explained to me some time ago why. I think it 
still applies, although I have not tried to test it. 

It is because the engine works directly on the memory used for the object (or 
something like that). The problem is, the engine parses the memory and creates 
a list of pointers to each chunk that you are looping by. (Someone correct me 
if I am wrong about this.) If you change what is in that memory at any time in 
the repeat loop, the pointers to the chunks you are looping by do not update 
with it. So if the contents of the memory shift, the pointers no longer point 
to what you think they do. 

In the past I often got garbage in the each variable at some point, leading me 
to believe that the OS did some house cleaning and the contents of the memory 
block was no longer valid. 

That has been my understanding, but if I am mistaken, or something has been 
updated in the repeat for each algorithm, I'll be happy to know it. 

Bob


On Apr 28, 2011, at 10:01 AM, John Dixon wrote:

> 
> 
> 
> 
>> Be careful with repeat for each. You cannot change the content of the object 
>> or block you are repeating through. "Unexpected results" is an 
>> understatement. You need to work with a copy, making sure you don't add or 
>> remove the each element (each word, each line etc.) else you get out of 
>> sync. 
>> 
>> Bob
> 
> Using 'repeat for each' with a counter is still faster than 'repeat with'
> 
>   put 1 into count
>   repeat for each line thisLine in fld 1
>      if line count of fld 1 = whatever then doSomething
>      add 1 to count
>   end repeat
> 
> be well
>                                         
> _______________________________________________
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to