File: ex_proc.adb

package info (click to toggle)
asis 2005-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 6,424 kB
  • ctags: 27
  • sloc: ada: 73,883; makefile: 201
file content (37 lines) | stat: -rw-r--r-- 872 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
--  this is an example procedure to be used in the
--  ASIS exercises
--
with Ex_Pack1; use Ex_Pack1;
procedure Ex_Proc is
   --  we have something to do in this example...
   --  Well, let's compute some factorials:

   subtype Test_Subtype is Integer range 1 .. 5;
   Res_Var  : Positive;
   Test_Var : Natural;

   function Factorial (N : Natural) return Positive;
   function Factorial (N : Natural) return Positive is
   begin
      if N = 0 then
         return 1;
      else
         return N * Factorial (N-1);
      end if;
   end Factorial;

begin
   for I in Test_Subtype loop
      Res_Var := Factorial (I);
      Put_Factorial (I, Res_Var);
   end loop;

   --  and now just try some value:
   Test_Var := 6;
   Res_Var  := Factorial (Test_Var);
   Put_Factorial (Test_Var, Res_Var);

   --  and anothe one:
   Put_Factorial (0, Factorial (0));

end Ex_Proc;