Using 'for each' to modify a container
Richard Gaskin
ambassador at fourthworld.com
Fri Oct 13 01:07:26 EDT 2006
Robert Sneidar wrote:
> put 1 into mcnt
> repeat for each line tline in mlist
> put empty into word 1 of tline
> put tline into line mcnt of mlist
> put mcnt + 1 into mcnt
> end repeat
FWIW, doing the data collection with the form "put...into line..." loses
much of the performance value of using "repeat for each", as it requires
the engine to crawl through mlist looking for mcnt number of CRs each
time through the loop.
To counter this, some years ago Scott Raney optimized the "put...after"
form, so you could have a second variable as a collector for things you
gather during the iteration, and would probably see a snappy performance
boost:
put empty into tNuList
repeat for each line tline in mlist
put empty into word 1 of tline
put tline &cr after tNuList
end repeat
This practice of collecting from one source and concatenating to a
different destination also takes care of the anomalies you noted when
attempting to modify the source container within a "repeat for each" loop.
--
Richard Gaskin
Fourth World Media Corporation
___________________________________________________________
Ambassador at FourthWorld.com http://www.FourthWorld.com
More information about the use-livecode
mailing list