0% found this document useful (0 votes)
26 views22 pages

Pascalzppt

This document provides an introduction and overview of Pascal programming including: - Simple example programs showing structure and use of reserved words - Data types like integer, string, char, boolean, and real - Declaring and using variables of different types - Comparing syntax between Pascal and Visual Basic - Control structures like IF-THEN-ELSE statements - Using comments in Pascal code

Uploaded by

Nnmj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views22 pages

Pascalzppt

This document provides an introduction and overview of Pascal programming including: - Simple example programs showing structure and use of reserved words - Data types like integer, string, char, boolean, and real - Declaring and using variables of different types - Comparing syntax between Pascal and Visual Basic - Control structures like IF-THEN-ELSE statements - Using comments in Pascal code

Uploaded by

Nnmj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 22

Pascal Programming

Written by Al.So. Software


solutions
Simple Program 1

begin

end.
Simple Program 2
program Test;
uses wincrt;
begin
writeln(‘Good Afternoon!’);
end.
Simple Program 2
Results:
Reserverd Words

These are the common reserved


words of pascal program. You
cannot use this as a variable name.

begin end program var string


if then else for to downto
while do repeat until
procedure function in
Program Title
program Test; {This is the program
title(you can omit it)}
begin
{Main Body}
end.
Data type
These are the common data type of pascal program.
Additional
Type Explanation Example
explanation

integer Whole numbers 3, 104, 0, -9

'Hello World',
string String variable (Text)
'456,4'
char Character (One character) 'b', 'A', '7'
Boolean Can only be True or
boolean True, False
variable False
(Floating point 4.0, -0.08, 48.6,
real Real numbers
numbers) 2.0E4
Declaring variable
program Test;
var i : integer;
var s : string;
var c : char;
var b : boolean;
var r : real;
begin
{Main Body}
end.
Declaring variable
program Test;
Uses wincrt;
var i : integer;
s : string;
c : char;
b : boolean;
r : real;
Begin
I := 0;
Writeln(i);
end.
Using Library
program Test;
uses wincrt; {Wincrt is a common
library in turbo pascal for i/o
manipulations wincrt.tpu}
var i : integer;
begin
{Main Body}
end.
Using Variables
program Test;
uses wincrt;
var i : integer;
Begin
Readln(i);
writeln(i);
end.
Using Variables
Results:
Using Variables
program Test;
uses wincrt;
var i : integer;
j : integer;
begin
i := 7;
j := 3;
i := i + j;
writeln(i);
end.
Using Variables
Results:
Comparing VB with Pascal
VB: Dim i as integer
Pascal: var i : integer;

VB: i = 10
Pascal: i := 10;

VB: ‘comment
Pascal: {Comment}/(*Comment*)
Comparing VB with Pascal
VB:
Dim j as integer
j = 10
If j = 10 then
print “J = 10”
Else
print “J <> 10”
End If
Comparing VB with Pascal
Pascal:
Uses wincrt;
var j : integer;
begin
j := 10;
if j = 10 then
writeln(‘J = 10’)
else
writeln(‘J <> 10’);
End.
IF…THEN…ELSE
program Test;
var j : integer;
begin
j := 10;
if j = 10 then
writeln(‘J = 10’) {*** No “;”}
else
writeln(‘J <> 10’);
writeln(‘End of program’);
end;
IF…THEN…ELSE
program Test;
var j : integer;
begin
j := 10;
if j = 10 then
The whole writeln(‘J = 10’)
If-Phrase else
writeln(‘J <> 10’);
writeln(‘End of program’);
end;
Complicated IF…THEN…ELSE
if i = 10 then
if j = 10 then
writeln(‘i = 10 and j = 10’)
else
writeln(‘i = 10 and j <> 10’)
else
writeln(‘i <> 10 and j <> 10’);
Correct Program
Complicated IF…THEN…ELSE
if i = 10 then
if j = 10 then
writeln(‘i = 10 and j = 10’)
else
writeln(‘i = 10 and j <>
10’);
else
writeln(‘i <> 10 and j <> 10’);
Wrong semicolon
(Syntax Error)
Comment
begin

{This is a comment}
(* This is also a comment*)

end.

You might also like