Delphi Error – E2097 BREAK or CONTINUE outside of loop

Delphi Compiler Error

E2097 BREAK or CONTINUE outside of loop

Reason for the Error & Solution

The compiler has found a BREAK or CONTINUE statement which is not contained inside a WHILE or REPEAT loop. These two constructs are only legal in loops.

program Produce;

  procedure Error;
    var i : Integer;
  begin
    i := 0;
    while i < 100 do
      INC(i);
      if odd(i) then begin
        INC(i);
  continue;
      end;
  end;

begin
end.

The example above shows how a continue statement could seem to be included in the body of a looping construct but, due to the compound-statement nature of The Delphi language, it really is not.

program Solve;

  procedure Error;
    var i : Integer;
  begin
    i := 0;
    while i < 100 do begin
      INC(i);
      if odd(i) then begin
        INC(i);
  continue;
      end;
    end;
  end;

begin
end.

Often times it is a simple matter to create compound statement out of the looping construct to ensure that your CONTINUE or BREAK statements are included.

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...