home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / programm / prog2 / moreloop.ada < prev    next >
Encoding:
Text File  |  1991-07-01  |  2.4 KB  |  93 lines

  1.                                        -- Chapter 5 - Program 2
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure MoreLoop is
  6.  
  7.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  8.    use Int_IO;
  9.  
  10.    type MY_TYPE is range 10..13;
  11.  
  12.    package My_Int_IO is new Text_IO.Integer_IO(MY_TYPE);
  13.    use My_Int_IO;
  14.  
  15.    My_Range      : MY_TYPE;
  16.    TWO           : constant INTEGER := 2;
  17.    THREE         : constant INTEGER := 3;
  18.    FOUR          : constant INTEGER := 4;
  19.    Height,Width  : INTEGER;
  20.    Special_Index : INTEGER;
  21.  
  22. begin
  23.  
  24.    for Index in MY_TYPE loop
  25.       Put("Going through the first loop");
  26.       Put(Index);
  27.       New_Line;
  28.    end loop;
  29.  
  30.    for Index in MY_TYPE'FIRST..MY_TYPE'LAST loop
  31.       Put("Going through the second loop");
  32.       Put(Index);
  33.       New_Line;
  34.    end loop;
  35.  
  36.    for Index in TWO..THREE**2 - FOUR loop    -- range is 2..5
  37.       Put("Going through the third loop");
  38.       Put(Index);
  39.       New_Line;
  40.    end loop;
  41.  
  42. Named_Loop:
  43.    for Height in TWO..FOUR loop
  44.       for Width in THREE..5 loop
  45.          if Height * Width = 12 then
  46.             exit Named_Loop;
  47.          end if;
  48.          Put("Now we are in the nested loop and area is");
  49.          Put(Height*Width);
  50.          New_Line;
  51.       end loop;
  52.    end loop Named_Loop;
  53.  
  54.    Special_Index := 157;
  55.    for Special_Index in 3..6 loop
  56.       Put("In the Special Index loop");
  57.       Put(Special_Index);
  58.       New_Line;
  59.    end loop;
  60.    Put("The Special Index loop is completed");
  61.    Put(Special_Index);
  62.    New_Line;
  63.  
  64. end MoreLoop;
  65.  
  66.  
  67.  
  68.  
  69. -- Result of execution
  70.  
  71. -- Going through the first loop 10
  72. -- Going through the first loop 11
  73. -- Going through the first loop 12
  74. -- Going through the first loop 13
  75. -- Going through the second loop 10
  76. -- Going through the second loop 11
  77. -- Going through the second loop 12
  78. -- Going through the second loop 13
  79. -- Going through the third loop      2
  80. -- Going through the third loop      3
  81. -- Going through the third loop      4
  82. -- Going through the third loop      5
  83. -- Now we are in the nested loop and area is     6
  84. -- Now we are in the nested loop and area is     8
  85. -- Now we are in the nested loop and area is    10
  86. -- Now we are in the nested loop and area is     9
  87. -- In the Special Index loop     3
  88. -- In the Special Index loop     4
  89. -- In the Special Index loop     5
  90. -- In the Special Index loop     6
  91. -- The Special Index loop is completed   157
  92.  
  93.