Sign in Join
Wiki copytemporary

Infinite loop/fr

English · Français · Suomi · Русский

Une boucle infinie (aussi appelée boucle sans fin) est une boucle qui ne finit jamais.$ Dans la boucle, les instructions sont répétées indéfiniment.

pascal
 while true do
   begin
   end;
pascal
 repeat
 until false;

Toutefois, de telles constructions sont des cas particuliers, dans la pratique assez rares. Un exemple est une boucle d'interrogation d'événement dans les programmes avec IHM graphique. La présence d'une boucle infinie peut être le signe d'une erreur de programmation.

Instruction Break

Les boucles "While True Do" ou "Repeat/fr Until/fr False/fr" semblent inifines au premier regard, mais il y a une manière de s'échapper de la boucle avec Break.

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

Break est aussi permis dans les boucles For/fr/For.

See also


From the Free Pascal wiki, page "Infinite loop/fr", as it stood on 2020-02-17 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 1, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.