On 2016-04-29 17:24, Richard Gaskin wrote:
In the rare cases where we might want to modify the string being
traversed, does the "repeat with i = 1 to..." form still allow that?

Yes - you can still modify the string being traversed with repeat for each, but the modifications won't actually affect what is being iterated over.

  repeat for each line tLine in tMyLines
    ... mutate tMyLines ...
  end repeat

Can be seen as being:

  local __tMyLines
  put tMyLines into __tMyLines
  repeat for each line tLine in __tMyLines
    ... mutate tMyLines ...
  end repeat

And due to the copy-on-write semantics in 7+, you don't actually pay for the 'invisible' temporary copy unless you actually do a modification.

In the case of 'repeat with' - the expressions involved are all evaluated before the loop starts:

  repeat with x = 1 to the number of lines in tMyLines
    ... mutate tMyLines ...
  end repeat

Can be seen as doing:

  local __start, __end
  put 1 into __start
  put the number of lines in tMyLines into __end
  repeat with x = __start to __end
    ... mutate tMyLines ...
  end repeat

As you can see, tMyLines (or even a copy of it) doesn't actually figure in the control part of the loop after it starts going.

Warmest Regards,

Mark.

--
Mark Waddingham ~ m...@livecode.com ~ http://www.livecode.com/
LiveCode: Everyone can create apps

_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to