Here's another approach that may run faster (DYO testing):
repeat for each line tMyLine in tData
-- Do something here to the text in tMyLine.
-- (In this context, tMyLine is effectively read-only.
-- To preserve selected data, put it into another
-- container, like this:)
if "z" is in tMyLine then
put tMyLine & cr after tSelectedData
end if
end repeat
-- when finished looping, tSelectedData contains all your good stuff.
Phil Davis
"James C. Wall" wrote:
>
> Dave Cragg wrote
>
> >For example, imagine you have list of data (in a variable called
> >tData) that is 1000 lines long, and you have to do some processing of
> >each line. The following script can turn out be very inefficient:
> >
> >put the number of lines of tData into tNumLines
> >repeat with i = 1 to tNumLines
> > ##do something to line i of tData
> >end repeat
> >
> >The problem is that Metacard has to count out the lines until it
> >finds the right one *each time* through the loop. (At least, that's
> >my understanding.) So as i gets bigger, it takes longer to find the
> >line on each loop, and so an exponential time increase.
>
> I use a lot of repeat loops and have not really considered efficiency
> until thi posting arrived. The approach I use is as follows
>
> put the number of lines of tData into x
> put 1 into i
> repeat x
> ##do something to line i of tData>end repeat
> add 1 to i
> end repeat
>
> Would this overcome the problem stated by Dave?
>
> Jim Wall
>
> *******************************************
> James C. Wall, Ph.D.
> Professor
> Department of Physical Therapy
> University of South Alabama
> 1504 Springhill Avenue, Room 1214
> Mobile AL 36604
>
> Phone: (334) 434 3575
> Fax: (334) 434 3822
> e-mail: [EMAIL PROTECTED]
>
> 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.
--
Phil Davis
---------------------------------
[EMAIL PROTECTED]
(503) 417-7930 x234
---------------------------------
Facilitator
Essentials of eBusiness Computing
Information Technology Institute
http://www.iti.com
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.