The Ada Program: decode.adb

  1 -- decode.adb:  program illustrating nested loop/exit
  2 
  3 -- From Cohen, "Ada as a Second Language," page 73.
  4 
  5 with Ada.Text_IO, Ada.Integer_Text_IO;
  6 use Ada;
  7 
  8 procedure Decode is
  9 
 10    End_Of_Line_Code    : constant Integer := 27;
 11    End_Of_Message_Code : constant Integer := 28;
 12    Next_Code           : Integer;
 13 
 14 begin
 15 
 16    Line_Loop:  loop           -- each line in the message
 17 
 18       Char_Loop:  loop        -- each character in the line
 19          Integer_Text_IO.Get (Next_Code);
 20          exit Char_Loop when Next_Code = End_Of_Line_Code;
 21          exit Line_Loop when Next_Code = End_Of_Message_Code;
 22          Text_IO.Put (Character'Val (Next_Code));
 23       end loop Char_Loop;
 24       Text_IO.New_Line;      -- handle the end-of-line code
 25 
 26    end loop Line_Loop;
 27    Text_IO.Put_Line ("#");   -- handle the end-of-message code
 28 
 29 end Decode;