Skip to content

Useless collection iteration (UseLessForEach)

Type Scope Severity Activated
by default
Minutes
to fix
Tags
Error BSL
OS
Critical Yes 2 clumsy

Description

The absence of an iterator in the loop body indicates either a useless iteration of the collection or an error in the loop body.

Examples

Incorrect:

For Each Iterator From Collection Loop

    ProcessElement(Collection);

EndLoop;

Correct

For Each Iterator From Collection Loop

    ProcessElement(Iterator);

EndLoop;
ProcessCollection(Collection);

Snippets

Diagnostic ignorance in code

// BSLLS:UseLessForEach-off
// BSLLS:UseLessForEach-on

Parameter for config

"UseLessForEach": false