Manuel Collado <address@hidden> wrote:
My point is about an hypothetical code that iterates over an array and
the iteration body modifies an element other that the current one. I.e.:
for (k in arr) {
... modify arr[j] ... # j != k
}
In that case the behavior may depend on the index iteration order. The
modified arr[j] may or may not be already iterated over.
Yes, this is undefined territory. A stronger question is what happens if
you insert new elements while iterating, will they be included or not?
Quite some time ago I fixed gawk so that before starting to iterate
it makes a list of what's in the array and only traverses that list;
elements added during the loop won't be included. But I'm not sure that
other awks can make that guarantee, and I doubt if POSIX requires this
behavior.