Introduction to the Pascal Programming Language

© 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 
                     page.

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


% cat PASCAL/intro_pencil-12.p
{ Introduction to the Pascal Programming Language
  Dr. Thomas W. MacFarland
  intro_pencil-12.p       
}

{ The purpose of this program is to:

  1.  Demonstrate integer math.

  2.  Demonstrate a for/do loop, a loop with a set number of 
      iterations.    
}

program Demonstrate_an_Additional_For_Do_Loop;

var A, B, C, D: integer;

begin

  A := -1;
  B :=  2;
  C := A + B;
  
  for D := A to C do begin
    write('D = ', D :3);
      if (D >= 1) then
        write(' D >= 1!'); writeln;
  end;

end.  { intro_pencil-12.p      } 
% pc PASCAL/intro_pencil-12.p
% a.out
D =  -1
D =   0
D =   1 D >= 1!

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

There have been visitors to this page since February 1, 1999.