Infinite loop

From Lazarus wiki

English (en) suomi (fi) français (fr) русский (ru)

An infinite loop (also known as an endless loop or unproductive loop or a continuous loop) is a loop which never ends. Inside loop, statements are repeated forever.


 while true do
   begin
   end;


 repeat
 until false;


Break statement

"While true do" or "repeat until false" loops looks infinite at first glance, but there may be a way to escape the loop through break.


var
  i:integer;
begin
  i := 0;
  while true do
    begin
      i := i + 1;
      if i = 100 then break;
    end;
end;
var
  i:integer;
begin
  i := 0;
  repeat
    i := i + 1;
    if i = 100 then break;
  until false;
end;

See also