Deleting an item when iterating through collection using the operator "For each ... In ... Do" (DeletingCollectionItem)
Don't delete elements of collection when iterating through collection using the operator For each ... In ... Do. Because it change index of next element.
Example:
For each Element In Collection Do
Collection.Delete(Element)
EndDo;
Alternatively, remove elements from the end:
IndexOf = Numbers.UBound();
While IndexOf >= 0 Do
If Numbers[IndexOf] < 10 Then
Numbers.Delete(IndexOf);
EndIf;
IndexOf = IndexOf – 1;
EndDo;