On 2018-06-25 15:29:23 +0000, Robert M. Münch said:

I have two foreach loops where the inner should change the iterator (append new entries) of the outer.

foreach(a, candidates) {
        foreach(b, a) {
                if(...) candidates ~= additionalCandidate;
        }
}

The foreach docs state that the collection must not change during iteration.

So, how to best handle such a situation then? Using a plain for loop?

Answering myself: If you implement an opApply using for() or while() etc. with a mutating aggregate, foreach can be used indirectly with mutating aggregates. Works without any problems.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster

Reply via email to