foreach / mutating iterator - How to do this?

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Jun 25 17:16:50 UTC 2018


On Mon, Jun 25, 2018 at 05:29:23PM +0200, Robert M. Münch via Digitalmars-d-learn wrote:
> 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?
[...]

Yes.


T

-- 
The fact that anyone still uses AOL shows that even the presence of options doesn't stop some people from picking the pessimal one. - Mike Ellis


More information about the Digitalmars-d-learn mailing list