ACR Rules

⌘K
  1. Home
  2. Docs
  3. ACR Rules
  4. Reliability (41)
  5. Lists should not be modified during iteration

Lists should not be modified during iteration

The behavior of a loop is unspecified if the underlying list is modified while the iteration is in progress. Therefore it should be avoided.

A workaround could be to store the items to be removed/added in a separate list and then remove/add them after the iteration is finished.

Non-compliant example:

Compliant example: