Script not accepting empty line

Sarah Reichelt sarahr at
Thu May 27 22:42:43 EDT 2004

> Sarah,
> Aren't there possible issues if one changes the contents of the 
> control variable inside a "repeat for each" structure?  For repeat for 
> each to work in this case wouldn't one need to make a copy of the 
> control variable for the repeat & make changes to the original?:
> on fillBlanks variableList
>   put 0 into lineNumber
>   get variableList
>   repeat for each line theLine in it
>     add 1 to x
>     if theLine is empty then put [whatEver] into line x of variableList
>   end repeat
> end fillBlanks

Yes Rob, that is a problem, so if you have a closer look at my script 
:-) you'll see that I use the contents of the original control variable 
to build a completely new variable to avoid this problem. In my script 
(which I have inserted below) "variable" is the name of the original 
variable used for the control loop. The contents of it, with something 
else is a line is empty, are used to build up "newVariable". The 
original "variable" is never changed at all. Your solution does things 
the other way around but both are valid ways around the potential 
problem with "repeat for each" loops. BTW as this is purely a 
demonstrator script, it has no way of actually getting any data in or 
out - I leave that up to the individual user :-)

on newAddNew
   put empty into newVariable
   repeat for each line L in variable
     if L is empty then
       -- insert the new data in place of the empty line
       put newData & cr after newVariable
       put L & cr after newVariable
     end if
   end repeat
   delete last line of newVariable  -- extra cr
end newAddNew


More information about the Use-livecode mailing list