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

  1.                         -- Chapter 18 - Programming example 1
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure CH18_1 is
  6.  
  7.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  8.    use Int_IO;
  9.  
  10.    Index : INTEGER;
  11.  
  12.    procedure Print_And_Decrement(Value : in     INTEGER) is
  13.    New_Value : INTEGER;
  14.    begin
  15.       Put("The value of the index is now");
  16.       Put(Value);
  17.       New_Line;
  18.       New_Value := Value - 1;
  19.       if New_Value > 0 then
  20.          Print_And_Decrement(New_Value);
  21.       end if;
  22.       Put("Following the recursive call, value =");
  23.       Put(Value);
  24.       New_Line;
  25.    end Print_And_Decrement;
  26.  
  27. begin
  28.    Index := 7;
  29.    Print_And_Decrement(Index);
  30. end CH18_1;
  31.  
  32.  
  33.  
  34.  
  35. -- Result of execution
  36.  
  37. -- The value of the index is now     7
  38. -- The value of the index is now     6
  39. -- The value of the index is now     5
  40. -- The value of the index is now     4
  41. -- The value of the index is now     3
  42. -- The value of the index is now     2
  43. -- The value of the index is now     1
  44. -- Following the recursive call, value =     1
  45. -- Following the recursive call, value =     2
  46. -- Following the recursive call, value =     3
  47. -- Following the recursive call, value =     4
  48. -- Following the recursive call, value =     5
  49. -- Following the recursive call, value =     6
  50. -- Following the recursive call, value =     7
  51.  
  52.