Skip to content

Latest commit

 

History

History
50 lines (36 loc) · 1.54 KB

DeletingCollectionItem.md

File metadata and controls

50 lines (36 loc) · 1.54 KB

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

Type Scope Severity Activated
by default
Minutes
to fix
Tags
Error BSL
OS
Major Yes 5 standard
error

Description

Don't delete elements of collection %s 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

Snippets

Diagnostic ignorance in code

// BSLLS:DeletingCollectionItem-off
// BSLLS:DeletingCollectionItem-on

Parameter for config

"DeletingCollectionItem": false