Using 'for each' to modify a container

Bill Marriott wjm at wjm.org
Wed Oct 11 08:34:47 CDT 2006


You shouldn't try to change the tires while the car is moving, and you 
shouldn't try to modify the entity being used as the basis of a repeat loop.

For example, if you were to say

repeat with i = 1 to 20
end repeat

you shouldn't try to modify i within the loop.

If you say

repeat for each line theLine in myVariable
end repeat

you shouldn't try to modify myVariable within the loop.

There are probably many possibilities for your solution, but I would 
probably do it this way:

put empty into newContainer
repeat for each line thisLine in vContainer
  put doSomeFunction(item -2 of thisLine) into item -2 of thisLine
  put thisLine & return after newContainer
end repeat
put char 1 to -2 of newContainer into vContainer

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 






More information about the use-livecode mailing list