4.3. Loop - JulTob/Ada GitHub Wiki

Loop

Infinite general loops:


loop
   --  . Do something ad infinitum .  --
   end loop;   
loop
   --  . Do something until condition .  --
   exit when bool_condition;
   end loop;    
-- exit when =
loop
   --  . Do something until condition .  --
   if bool_condition then 
      exit; 
      end if;
   end loop;   
          
Loop_Name : loop
   --  . Do something .  --
   end loop Loop_Name;


Loop_Name : loop
   --  .Do something?  --
   exit Loop_Name  when bool_condition;
   --  .Do something?  --
   end loop Loop_Name;



Main_Loop : loop
   --.Do something?--
   Inner_Loop: loop
      --.Do something?--
      exit Main_Loop when bool_condition;
      -- Leaves all nested loops
      --.Do something?--
      end loop Inner_Loop;
   --.Do something?--
   end loop Main_Loop;



Index := 1;
Loop
   Index := index + 10;
   If index > 50 then exit; end if;
   End loop;



Index := 1;
Loop
   Index := index + 10;
   Exit when index > 50;
   End loop;



Index := 1;
bigLoop : loop
   index := index + 1;
   loop
      index := index + 1;
      exit when index = 8;
      if index > 100 then exit bigloop; end if;
      end loop;
   end loop bigloop;

  loop
    Ada.Text_IO.Put_Line("Inside of the infinite loop!");
    delay 0.5;
    end loop;

You can have more than one exit statement.