Infinite loop

From Free Pascal wiki
Revision as of 07:56, 14 October 2015 by Djzepi (talk | contribs) (Created page with "{{Infinite loop}} 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 ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

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