in reply to changing array size in foreach loop: is it safe?

Elements in for are flattened to a list before processing. The array should be ignored after the initial entry into the loop--it will only process the list it created. It should be safe to add elements to the array, though I would hesitate to rely on this behavior.

"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Replies are listed 'Best First'.
Re^2: changing array size in foreach loop: is it safe?
by Roy Johnson (Monsignor) on Feb 07, 2005 at 19:48 UTC
    That's not the behavior the OP was seeing, so you definitely can't rely on it. The iterator will process elements that were added on to the end of the array within the loop.

    Caution: Contents may have been coded under pressure.