Using 'for each' to modify a container
Robert Sneidar
bobs at twft.com
Fri Oct 13 00:27:22 EDT 2006
I have experienced no corruption of data, but I certainly have had
unexpected behavior. Given:
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
As each iteration of the repeat loop progresses I find the data I get
in tline is shifted to the right by the length of the deleted data.
I can only think an index is created at the start of the loop which
points to a memory location, and since the data is shifting while the
pointer does not, you must not change the contents of mlist until the
loop is finished.
So I learned when using this form to either store the contents of
mlist in a temporary variable and modify that, or build a temporary
variable as I go until the loop is complete. Then I put the contents
of that variable into mlist if that's what I want.
I have had no problems changing the contents of tline.
Bob Sneidar
IT Manager
Logos Management
Calvary Chapel CM
On Oct 11, 2006, at 5:45 AM, Mark Powell wrote:
> I want to use the 'for each' form of the repeat loop, but don't
> know how
> to use it to modify data within a container. For example:
>
> repeat for each line thisLine in vContainer
> put doSomeFunction(item -2 of thisLine) into item -2 of thisLine
> --how do I get the change back into vContainer?
> end repeat
>
> Thanks!
>
> Mark Powell
> mark_powell (at symbol) symantec.com
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
More information about the use-livecode
mailing list