Skip to content

Latest commit

 

History

History
30 lines (22 loc) · 870 Bytes

DeletingCollectionItem.md

File metadata and controls

30 lines (22 loc) · 870 Bytes

Deleting an item when iterating through collection using the operator "For each ... In ... Do" (DeletingCollectionItem)

Description

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;

Sources