foreach / mutating iterator - How to do this?

Robert M. Münch robert.muench at saphirion.com
Mon Jun 25 15:29:23 UTC 2018


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?

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



More information about the Digitalmars-d-learn mailing list