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

  1.                                        -- Chapter 5 - Program 3
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure IfDemo is
  6.  
  7.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  8.    use Int_IO;
  9.  
  10. begin
  11.    for Index in 1..7 loop  -- This contains two simple if statements
  12.       Put("Index is ");
  13.       Put(Index,3);
  14.       if Index < 4 then
  15.          Put(" so is less than 4");
  16.       end if;
  17.       if Index > 5 then
  18.          Put(" so is more than 5");
  19.       end if;
  20.       New_Line;
  21.    end loop;
  22.    New_Line;
  23.  
  24.    for Index in 13..17 loop  -- This contains an else clause
  25.       Put("Index is");
  26.       Put(Index,3);
  27.       if Index < 15 then
  28.          Put_Line(" and is less than 15.");
  29.       else
  30.          Put_Line(" and is 15 or greater.");
  31.       end if;
  32.    end loop;
  33.    New_Line;
  34.  
  35.    for Index in 13..17 loop  -- This introduces the elsif statement
  36.       Put("Index is");
  37.       Put(Index,3);
  38.       if Index < 15 then
  39.          Put_Line(" and is less than 15.");
  40.       elsif Index = 15 then
  41.          Put_Line(" and is 15.");
  42.       elsif Index = 16 then
  43.          Put_Line(" and is 16.");
  44.       else
  45.          Put_Line(" and is greater than 16.");
  46.       end if;
  47.    end loop;
  48.    New_Line;
  49.  
  50. -- This final group of statements contains a loop with a nested if
  51. --   statement, and a loop within the the else part of the nested
  52. --   if statement.
  53.  
  54.    for Index in 13..17 loop
  55.       Put("Index is");
  56.       Put(Index,3);
  57.       if Index < 16 then
  58.          if Index > 14 then
  59.             Put(" and is less than 16 and greater than 14.");
  60.          else
  61.             Put(" and is less than or equal to 14.");
  62.          end if;
  63.       else
  64.          Put(" and is 16 or greater.");
  65.          for New_Index in 222..224 loop
  66.            Put(" stutter");
  67.          end loop;
  68.       end if;
  69.       New_Line;
  70.    end loop;
  71.  
  72. end IfDemo;
  73.  
  74.  
  75.  
  76.  
  77.  
  78. -- Result of execution
  79.  
  80. -- Index is   1 so is less than 4
  81. -- Index is   2 so is less than 4
  82. -- Index is   3 so is less than 4
  83. -- Index is   4
  84. -- Index is   5
  85. -- Index is   6 so is more than 5
  86. -- Index is   7 so is more than 5
  87. --
  88. -- Index is 13 and is less than 15.
  89. -- Index is 14 and is less than 15.
  90. -- Index is 15 and is 15 or greater.
  91. -- Index is 16 and is 15 or greater.
  92. -- Index is 17 and is 15 or greater.
  93. --
  94. -- Index is 13 and is less than 15.
  95. -- Index is 14 and is less than 15.
  96. -- Index is 15 and is 15.
  97. -- Index is 16 and is 16.
  98. -- Index is 17 and is greater than 16.
  99. --
  100. -- Index is 13 and is less than or equal to 14.
  101. -- Index is 14 and is less than or equal to 14.
  102. -- Index is 15 and is less than 16 and greater than 14.
  103. -- Index is 16 and is 16 or greater. stutter stutter stutter
  104. -- Index is 17 and is 16 or greater. stutter stutter stutter
  105.  
  106.