.NET – Remove from a List within a ‘foreach’ loop
You can iterate through the list backwards: for (int i = myList.Count – 1; i >= 0; i–) { if (whatever) myList.RemoveAt(i); } In response to your comment about wanting to quit when you find an item that you’re NOT removing, then just using a while loop would be the best solution.