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-15.p
{ Introduction to the Pascal Programming Language
  Dr. Thomas W. MacFarland
  intro_pencil-15.p       
}

{ The purpose of this program is to:

  1.  Demonstrate Boolean math.

  2.  Demonstrate the : symbol to format the printout of 
      Boolean true and false output.
}

program Demonstrate_Boolean_Math;

var A, B, C : boolean;
    D, E    : integer;

begin

   D := 0;
   E := 1;
   A := D = E;    
   B := D = (E + 1);  
   C := D < E;       

   write('A =  ',A :6, '   '); write('B =  ',B :6, '   ');
   write('C =  ',C :6, '   '); write('D =  ',D :6, '   '); 
   write('E =  ',E :6, '   '); writeln;

   A := B and C;

   write('A =  ',A :6, '   '); write('B =  ',B :6, '   ');
   write('C =  ',C :6, '   '); writeln;

   A := B and not C;

   write('A =  ',A :6, '   '); write('B =  ',B :6, '   ');
   write('C =  ',C :6, '   '); writeln;

   A := B or C;

   write('A =  ',A :6, '   '); write('B =  ',B :6, '   ');
   write('C =  ',C :6, '   '); writeln;

   A := (B and C) or not (C);

   write('A =  ',A :6, '   '); write('B =  ',B :6, '   '); 
   write('C =  ',C :6, '   ');
   writeln;

end.  { intro_pencil-15.p      } 
% pc PASCAL/intro_pencil-15.p
% a.out
A =   false   B =   false   C =    true   D =       0   E =       1   
A =   false   B =   false   C =    true   
A =   false   B =   false   C =    true   
A =    true   B =   false   C =    true   
A =   false   B =   false   C =    true   

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

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