EngradeWikis › Pascal Program

Pascal Program

Basic Layout of a Pascal Program

Program nameofprogram (input, output); { program header }

{ This program shows how a Pascal program is to be set up
Written by S. Ollivierre February 16, 2009 } { This is a comment }

Uses wincrt;

{ next comes the declaration section for types, constants and reals }
{ in the next section one sets up any constants that may be needed by the program,
all programs do not have constants }

CONST nameofconstant1 = value ;
nameofconstant2 = value ;

e.g. months = 12 ;
pi = 3.14 ;

{ in the next section one sets up all the variables which will be needed in the program }
VAR variablename : data type;

e.g. Number : integer;
num1, num2, age, sum : integer;
fname, lname, address : string;
option, choice : char;
found : boolean;
billamount, change, total : real;

BEGIN { Here begins the main program – i.e. the statements to be executed }
Clrscr; { provides a blank screen each time the program is run }
<Pascal statements here>
<more statements here>
<still more statements can go here>

Readln; { pauses the screen so that the output can be seen }

The program header is compulsory
The CONST and VAR sections are optional but most programs do have variables so a VAR section is usually needed.
The statements are surrounded by begin and end. Note that there is a full stop after the final end
Every Pascal statement ends with a semicolon
« Prev Page