Difference between revisions of "Infinite loop/fr"

From Free Pascal wiki
Jump to navigationJump to search
(Created page with "{{Infinite loop}} 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. <...")
 
m (Fixed syntax highlighting)
 
Line 4: Line 4:
 
Dans la boucle, les instructions sont répétées indéfiniment.
 
Dans la boucle, les instructions sont répétées indéfiniment.
  
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
  while true do
 
  while true do
 
   begin
 
   begin
 
   end;
 
   end;
 
</syntaxhighlight>
 
</syntaxhighlight>
<br>
+
 
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
  repeat
 
  repeat
 
  until false;
 
  until false;
Line 20: Line 20:
  
 
Les boucles "[[While/fr|While]] [[True/fr|True]] [[Do/fr|Do]]" ou "[[Repeat/fr|Repeat/fr]] [[Until/fr|Until/fr]] [[False/fr|False/fr]]" semblent inifines au premier regard, mais il y a une manière de s'échapper de la boucle avec [[Break/fr|Break]].
 
Les boucles "[[While/fr|While]] [[True/fr|True]] [[Do/fr|Do]]" ou "[[Repeat/fr|Repeat/fr]] [[Until/fr|Until/fr]] [[False/fr|False/fr]]" semblent inifines au premier regard, mais il y a une manière de s'échapper de la boucle avec [[Break/fr|Break]].
<syntaxhighlight>
+
 
 +
<syntaxhighlight lang=pascal>
 
var
 
var
 
   i:integer;
 
   i:integer;
Line 32: Line 33:
 
end;
 
end;
 
</syntaxhighlight>
 
</syntaxhighlight>
<br>
+
 
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
var
 
var
 
   i:integer;
 
   i:integer;

Latest revision as of 11:54, 17 February 2020

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

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.

 while true do
   begin
   end;
 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.

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;

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


See also