Back

PRF006

Inefficient loop condition

Object Pascal — Delphi & Free Pascal
Info
Performance

Calling Length or Count in every loop iteration re-evaluates the expression unnecessarily

calling Length or Count in every loop iteration re-evaluates the expression unnecessarily.

Why this severity

calling Length or Count in every loop iteration re-evaluates the expression unnecessarily.


Known false positives

collections whose count changes during iteration by design.

Remediation example

var
  N: Integer;
begin
  N := Length(Items);
  for I := 0 to N - 1 do
    Process(Items[I]);
end;

Reconnecting… Connection lost. Reload