goofy question about "repeat for each"

Bob Sneidar bobsneidar at iotecdigital.com
Thu Mar 28 12:58:30 EDT 2019


cc does not change. j only changes in each iteration when you add 1 to item 1 of j. Next iteration j will be set to the next line in cc. 

LC History: It used to be when repeat for each was first implemented, you were playing with fire to change the content of either cc or j, as the repeat for each construct actually indexed the memory holding cc. Changing cc could (and usually did) force the OS to make another copy of cc SOMEWHERE ELSE in memory, thereby releasing the prior handle (if I understand correctly), and depending on whether or not the OS overwrote the memory that once contained cc, the contents could be anything. 

Since then it's been reworked so that doesn't happen. 

Bob S


> On Mar 25, 2019, at 12:31 , jbv via use-livecode <use-livecode at lists.runrev.com> wrote:
> 
> Hi list,
> 
> I have a list of values such as :
>  540,20
>  542,22...
> one per line in a variable named cc.
> 
> Now I'm running the following loop :
>   repeat for each line j in cc
>     add 1 to item 1 of j
>     put return & j after var2
>   end repeat
> 
> goofy question : does each iteration of the loop
> change the values of each line of cc, or does it
> only change the value of j ?





More information about the use-livecode mailing list