home *** CD-ROM | disk | FTP | other *** search
- -- Chapter 18 - Programming example 1
- with Text_IO;
- use Text_IO;
-
- procedure CH18_1 is
-
- package Int_IO is new Text_IO.Integer_IO(INTEGER);
- use Int_IO;
-
- Index : INTEGER;
-
- procedure Print_And_Decrement(Value : in INTEGER) is
- New_Value : INTEGER;
- begin
- Put("The value of the index is now");
- Put(Value);
- New_Line;
- New_Value := Value - 1;
- if New_Value > 0 then
- Print_And_Decrement(New_Value);
- end if;
- Put("Following the recursive call, value =");
- Put(Value);
- New_Line;
- end Print_And_Decrement;
-
- begin
- Index := 7;
- Print_And_Decrement(Index);
- end CH18_1;
-
-
-
-
- -- Result of execution
-
- -- The value of the index is now 7
- -- The value of the index is now 6
- -- The value of the index is now 5
- -- The value of the index is now 4
- -- The value of the index is now 3
- -- The value of the index is now 2
- -- The value of the index is now 1
- -- Following the recursive call, value = 1
- -- Following the recursive call, value = 2
- -- Following the recursive call, value = 3
- -- Following the recursive call, value = 4
- -- Following the recursive call, value = 5
- -- Following the recursive call, value = 6
- -- Following the recursive call, value = 7
-
-