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

  1.                       -- Chapter 9 - Programming exercise 1
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure CH09_1 is
  6.  
  7.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  8.    use Int_IO;
  9.  
  10.    Index, Count : INTEGER;
  11.  
  12. begin
  13.    Index := 27;
  14.    Count := 33;
  15.    Put("In the main block      - values are");
  16.    Put(Index);                                -- CH09_1.Index
  17.    Put(Count);                                -- CH09_1.Count
  18.    New_Line;
  19.  
  20.    declare
  21.       Index, Stuff : INTEGER := -345;
  22.  
  23.       procedure Output_A_Line is
  24.       begin
  25.          Put_Line("This is in the new block procedure");
  26.       end Output_A_Line;
  27.  
  28.    begin
  29.       Index := 157;
  30.       Put("In the embedded block  - values are");
  31.       Put(CH09_1.Index);                      -- CH09_1.Index
  32.       Put(Index);                             -- local Index
  33.       Put(Stuff);                             -- local Stuff
  34.       Put(Count);                             -- CH09_1.Count
  35.       New_Line;
  36.       Output_A_Line;
  37.    end;
  38.  
  39.    Put("Back to the main block - values are");
  40.    Put(Index);                                -- CH09_1.Index
  41.    Put(Count);                                -- CH09_1.Count
  42.    New_Line;
  43.  
  44.    Who:                                       -- Block name
  45.    declare
  46.       Index, Stuff : INTEGER := -345;
  47.    begin
  48.       Index := 157;
  49.       Put("In the block named Who - values are");
  50.       Put(CH09_1.Index);                      -- CH09_1.Index
  51.       Put(Index);                             -- Who.Index
  52.       Put(Who.Index);                         -- Who.Index
  53.       Put(Stuff);                             -- Who.Stuff
  54.       Put(Who.Stuff);                         -- Who.Stuff
  55.       Put(Count);                             -- CH09_1.Count
  56.       New_Line;
  57.    end Who;
  58.  
  59.    Put("Back to the main block - values are");
  60.    Put(Index);                                -- CH09_1.Index
  61.    Put(Count);                                -- CH09_1.Count
  62.    New_Line;
  63.  
  64. end CH09_1;
  65.  
  66.  
  67.  
  68.  
  69. -- Result of execution
  70.  
  71. -- In the main block      - values are   27   33
  72. -- In the embedded block  - values are   27  157 -345   33
  73. -- This is in the new block procedure
  74. -- Back to the main block - values are   27   33
  75. -- In the block named Who - values are   27  157  157 -345 -345   33
  76. -- Back to the main block - values are   27   33
  77.  
  78. -- Note; some blanks were removed to fit the data in 70 columns.
  79.  
  80.