Show: Object Pascal C++
Display Preferences

E2097 BREAK or CONTINUE outside of loop (Object Pascal)

From Appmethod Topics
Jump to: navigation, search

Go Up to Error and Warning Messages (Object Pascal) Index

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

Personal tools
In other languages