1
PROGRAMMING USING
PASCAL
Pascal using EZY Pascal
PASCAL PROGRAMMING
2
Pascal is a high-level 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:
1. The program must have a name. 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
2. User identifiers outline. User identifiers are names
created by the programmer. These include variable names,
the program name, names of symbolic constants or names
of sub-programs.
3. Every Pascal statement (except begin) is terminated by a semi-colon. The
last statement in the program (that is, the end statement) is terminated by a
period.
Semi-colon ;
4. In Pascal the assignment symbol is ":=". This corresponds to the "= or
arrow "in our pseudocode.
5. The begin/end keyword pair is used to delimit the body of the program as
well as logical blocks within the program.
For example, when multiple statements are to be executed within a while
loop, such statements are encapsulated within a begin/end pair. For every
begin in a program, there must be a corresponding end statement.
6. Comments are used to document a program internally, to aid in the
understanding of the program statements and segments. Comments in
Pascal are enclosed within curly braces {....}.
Keywords (or reserved words)
Begin and end are examples of keywords used in
Pascal.
Keywords are words that have special meaning in
Pascal and can only be used in the predefined
context. That is, they cannot be used as variable
names or in any other context.
Other keywords are program, type, var, const,
readkey, readln, writeIn, write.
Keywords (or reserved words)
6
What are variables?
7
Declaring Variables in pascal
• Variables must always be declared in the variable
declaration section prior to their use in the
program. Variables are declared in Pascal by
specifying the keyword var followed by a list of
variables, a semi-colon and the data type.
• For example, var
numl: integer;
average: real;
Declaring Constants
Constants are like variables except that their values can't
change. You assign a value to a constant when you create it.
const is used instead of var when declaring a constant.
Constants are used for values that do not change such as the
value of pi.
Example:
program Variables;
const
pi: Real = 3.14;
var
c, d: Real;
10
11
12
13
Basic layout of a Pascal program
14
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.