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

  1.                                        -- Chapter 5 - Program 4
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure CaseDemo is
  6.  
  7.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  8.    use Int_IO;
  9.  
  10. begin
  11.    for How_Many in 4..13 loop
  12.       Put("We now have ");
  13.       Put(How_Many,3);
  14.       Put(" widgets, ");
  15.       case How_Many is
  16.          when 4..6    => Put("which is too few.");
  17.          when 7|9     => Put("but we don't need 7 or 9.");
  18.          when 13      => Put("but that is too many.");
  19.          when 8|10|12 => Put("which is a large even number.");
  20.          when 11      => Put("enough for a football team.");
  21.       end case;
  22.       New_Line;
  23.    end loop;
  24.    New_Line;
  25.  
  26.    for How_Many in 100..105 loop
  27.       Put("It is now ");
  28.       Put(How_Many,3);
  29.       Put(" ");
  30.       case How_Many is
  31.          when 100 => Put("The value is 100, and useless.");
  32.          when 101 => for Index in 2..5 loop
  33.                         Put("Puppy ");
  34.                      end loop;
  35.          when 103 => if TRUE then
  36.                         Put("Of course TRUE will always be true.");
  37.                      end if;
  38.          when 105 => null;
  39.          when others => Put("This is one of those not defined.");
  40.       end case;
  41.       New_Line;
  42.    end loop;
  43. end CaseDemo;
  44.  
  45.  
  46.  
  47.  
  48. -- Result of execution
  49.  
  50. -- We now have   4 widgets, which is too few.
  51. -- We now have   5 widgets, which is too few.
  52. -- We now have   6 widgets, which is too few.
  53. -- We now have   7 widgets, but we don't need 7 or 9.
  54. -- We now have   8 widgets, which is a large even number.
  55. -- We now have   9 widgets, but we don't need 7 or 9.
  56. -- We now have  10 widgets, which is a large even number.
  57. -- We now have  11 widgets, enough for a football team.
  58. -- We now have  12 widgets, which is a large even number.
  59. -- We now have  13 widgets, but that is too many.
  60. --
  61. -- It is now 100 The value is 100, and useless.
  62. -- It is now 101 Puppy Puppy Puppy Puppy
  63. -- It is now 102 This is one of those not defined.
  64. -- It is now 103 Of course TRUE will always be true.
  65. -- It is now 104 This is one of those not defined.
  66. -- It is now 105
  67.  
  68.