1
PROGRAMMING USING
PASCAL
2
Pascal is a programming language used to
construct computer programs. It uses simple
English like statements and it allows the
programming experience to be simple
particularly for beginners.
When writing programs in Pascal some simple
rules are required to be followed:
3
1. Program name:
All programs must have a name
Program names must begin with a letter of the
alphabet
Spaces are not allowed in program names
4
2. Variable and constant declaration:
All variables and constants to be used the program
must be declared
Variables and constants are declared in the program
head
Pascal keywords cannot be used as variable names
5
3. The program must begin and end
4. All statements must end with a semicolon(;)
5. All programs must end with the keyword end
followed by a full stop (end.).
Basic layout of a Pascal program
6
Program nameofprogram (input, output); Program name
Program
Header
Const //declare constants here Constant and Variable
Var //declare variables here declarations
Begin
// place statements inside here. Main of the program
End.
Input values
7
Values are input into variables using the
readln keyword, followed by the name of the
variable in a pair of brackets.
Example:
Readln(x)
Above a value is read into a variable called x.
Output values from variables and constants
8
Values are output from variables or constants
using the writeln or write keywords, followed
by the name of the variable or constant in a
pair of brackets.
Example:
Writeln(x)
Above the value which is currently stored in the
variable/constant x will be displayed on the
computer screen.
Output messages to the computer screen.
9
Messages can be output to the computer
screen using the write or writeln keywords.
The message should be enclosed in a pair of
single quotes within a pair of brackets.
Example:
Writeln(‘hello world’);
The statement above will print HELLO WORLD
on the computer screen.
Writeln / Write
10
Writeln
Prints information in a new line.
Write
Prints information without putting it into a new
line.
Assign values to variables:
11
Values are assigned to variables using the
assignment symbol(:=).
Example:
x:=9;
Above the value 9 is assigned to a variable called
x.
Assign values to constants
12
Values are assigned constants using the equal
sign (=).
Example
X=9;
Above the value 9 is assigned to constant x.