Repeat loop index

Dar Scott dsc at swcp.com
Mon Jul 14 17:22:01 EDT 2003


On Monday, July 14, 2003, at 03:45 PM, erik hansen wrote:

> put (the number of lines in tText) into tTotal
> repeat with i = 1 to tTotal
>    doSomething(line i of tText)
> end repeat
>
> be any faster than:
>
> put 0 into tCounter
> repeat for each line of tText
>   add 1 to tCounter
>   doSomething(line tCounter of tText)
> end repeat

It is slightly faster, but it is not the question at hand as I  
understand it.

I think the situation is this:

put (the number of lines in tText) into tTotal
repeat with i = 1 to tTotal
    doSomething( i, line i of tText )  -- use both # & line
end repeat

is slower than

put 0 into tCounter
repeat for each line tLine of tText
   add 1 to tCounter
   doSomething(tCounter, tLine)  -- use both # & line
end repeat

The first one much climb through the tText every cycle to get to the  
desired line.

Dar

************************************************************************ 
****
   Dar Scott Consulting    http://www.swcp.com/dsc/    Programming  
Services
************************************************************************ 
****




More information about the use-livecode mailing list