Delphi Error – H2135 FOR or WHILE loop executes zero times – deleted

Delphi Compiler Error

H2135 FOR or WHILE loop executes zero times – deleted

Reason for the Error & Solution

The compiler has determined that the specified looping structure will not ever execute, so as an optimization it will remove it. Example:

program Produce;
(*$HINTS ON*)

  var
    i : Integer;

begin
  i := 0;
  WHILE FALSE AND (i < 100) DO
    INC(i);
end.

The compiler determines that ‘FALSE AND (i < 100)’ always evaluates to FALSE, and then easily determines that the loop will not be executed.

program Solve;
(*$HINTS ON*)

  var
    i : Integer;

begin
  i := 0;
  WHILE i < 100 DO
    INC(i);
end.

The solution to this hint is to check the boolean expression used to control while statements is not always FALSE. In the for loops you should make sure that (upper bound – lower bound) >= 1.

You may see this warning if a FOR loop increments its control variable from a value within the range of Longint to a value outside the range of Longint. For example:

var I: Cardinal;
begin
  For I := 0 to $FFFFFFFF do
...

This results from a limitation in the compiler which you can work around by replacing the FOR loop with a WHILE loop.

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Delphi Compiler Error E2313 Attribute – Known attribute cannot specify properties Reason for the Error & Solution No further information...
Delphi Compiler Error E2379 Virtual methods not allowed in record types Reason for the Error & Solution No further information...
Rodrigo , one of the long time Delphi Developer has been working on one of his personal project “Delphi IDE...