in reply to changing array size in foreach loop: is it safe?
If any element of LIST is an lvalue, you can modify it by modifying VAR inside the loop. Conversely, if any element of LIST is NOT an lvalue, any attempt to modify that element will fail. In other words, the foreach loop index variable is an implicit alias for each item in the list that you're looping over.That's referring to the elements of the list, not the list itself. If you're worried, make another array, add new elements onto that, then combine the arrays when it's done.
|
|---|