I would like to loop through my collection using a for-in loop, but read it’s unsafe to modify the content of my data structure (which would be either a dictionary or an array) within such loop. Is that correct? Could it have any side effects? Should I use a for loop with index instead? Thank you.
Share
As long as you don’t add or delete objects, you are OK. That is, if an object in the collection is a mutable object, and you change something about that, its fine. Its only when you go deleting, adding or replacing objects to the collection that you get into trouble.