Advanced Pascal Programming Language Problems

© 1998 by Dr. Thomas W. MacFarland -- All Rights Reserved

     Instructions:   Review the following program and see if you can 
                     predict the outcome by completing a "pencil 
                     trace" of the code.  

                     Program output is provided at the end of this 

     Compiler:       The program was prepared using Standard Pascal 
                     on a UNIX-based host computer.

% cat PASCAL/advanced_pencil-08.p
{ Advanced Pascal Programming Language Exercises
  Dr. Thomas W. MacFarland

{ The purpose of this program is to:

  1.  Demonstrate the use of recursion to produce highly
      compact code.

program Demonstrate_Recursion_1;

var Tally : integer;

procedure Do_Something(Z : integer);
   writeln('Z   = ', Z:8);
   Z := Z + 4;         
   if Z <= 100 then
end; {end procedure Do_Something}

begin  (* main program *)
   Tally := 88;
end.  {advanced_pencil-08.p}
%  pc PASCAL/advanced_pencil-08.p
%  a.out
Z   =       88
Z   =       92
Z   =       96
Z   =      100

Please send comments or suggestions to Dr. Thomas W. MacFarland

There have been [an error occurred while processing this directive] visitors to this page since February 1, 1999.