home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / m2t-2.zip / ANSWERS / CH05E2.MOD < prev    next >
Text File  |  1989-01-18  |  1KB  |  50 lines

  1.                             (* Chapter 5 - Programming exercise 2 *)
  2.                                          (* Chapter 5 - Program 7 *)
  3. MODULE CH05E2;
  4.  
  5. FROM InOut IMPORT WriteString, WriteInt, WriteLn;
  6.  
  7. VAR Count : INTEGER;
  8.  
  9. PROCEDURE PrintAndDecrement(Index : INTEGER);
  10. BEGIN
  11.    WriteString("The value of the Index is");
  12.    WriteInt(Index,5);
  13.    WriteLn;
  14.    Index := Index - 1;
  15.    IF Index > 0 THEN
  16.       PrintAndDecrement(Index);
  17.    END;
  18.    WriteString("The value of the Index is");
  19.    WriteInt(Index,5);
  20.    WriteLn;
  21. END PrintAndDecrement;
  22.  
  23. BEGIN    (* Main program *)
  24.    Count := 7;
  25.    PrintAndDecrement(Count);
  26. END CH05E2.
  27.  
  28.  
  29.  
  30.  
  31. (* Result of execution
  32.  
  33. The value of the Index is    7
  34. The value of the Index is    6
  35. The value of the Index is    5
  36. The value of the Index is    4
  37. The value of the Index is    3
  38. The value of the Index is    2
  39. The value of the Index is    1
  40. The value of the Index is    0
  41. The value of the Index is    1
  42. The value of the Index is    2
  43. The value of the Index is    3
  44. The value of the Index is    4
  45. The value of the Index is    5
  46. The value of the Index is    6
  47.  
  48. *)
  49.  
  50.