PASCAL - GR 11
PASCAL - GR 11
Programming Language
By
Sisira Palihakkara
Pascal Overview
Easy to learn.
Structured language.
Menu Bar
Project Name
Close Button
Window Switch
Button
Code Window
Bottom
Menu
Row, Column
Number Scroll Bars
Turbo Pascal 7 IDE
validAge = 21;
e=2.7182818;
velocityLight = 3.0E+10;
Operator = '+';
president = 'Johnny Depp';
Operators
An operator is a symbol that tells the compiler to
perform specific mathematical or logical manipulations.
Pascal allows the following types of operators:
Arithmetic operators
Relational operators
Boolean operators
Bit operators
Set operators
String operators
Arithmetic Operators
Assume variable A holds 10 and variable B holds 20, then:
+ Addition A + B 30
- Subtraction A – B 10
* A * B 200
Multiplication
1 not
In this example sample is the program header and starts with the keyword
“Program”.
Input and output words are parameters showing that the program produces input
and output. It is optional.
Constant Declaration Section
program HelloWorld;
uses crt;
(* Here the main program block starts *)
Begin
Clrscr;
writeln('Hello, World!');
readkey;
end.
Parts of a Pascal program:
Simple selection
Types Selection Control structures
if-then Statement
Syntax:-
If the boolean expression condition evaluates to true, then the block of code
inside the if statement will be executed.
Pascal assumes any non-zero and non-null values as true, and if it is either
zero or null, then it is assumed as false value.
Flow Diagram for If .. then
Example – If - then
else Statement
The loop is never executed, if the condition is tested and the result is false, the
loop body will be skipped and the first statement after the while loop will be
executed.
while-do loop Sample
For-do LOOP
A for-do loop allows you to write a loop that needs to
execute a specific number of times.
Syntax:
Where,
array-identifier indicates the name of the array type.
index-type specifies the subscript of the array; it can be
any scalar data type except real
element-type specifies the types of values that are going
to be stored.
Example Arrays
begin
if x < y then
m:= x
else
m:= y;
if z < m then
m:= z;
end; { end of procedure findMin }
begin
writeln(' Enter three numbers: ');
readln( a, b, c);
findMin(a, b, c, min); (* Procedure call *)