2. Out line:
• About Pascal (programming language)…..
• General Program Skeleton……
• Pascal Hello World Example……
•Decision Making In Pascal…….
• loop in pascal………
3. About Pascal (programming language)…..
- is a historically influential imperative and procedural
programming language.
- designed in 1968-1969 and published in 1970 by Niklaus With as a
small and efficient language intended to encourage good
programming practices using structured programming and data
structuring.
4. General Program Skeleton
• The basic syntax for a Pascal program:
program name of the program]
var global variable declaration DloCk
function (function declarations )
ocau variables begin
end
procedure procedure declarations
local
Varlables
begin
...
begin ( main program block starts)
end.
5. Pascal Hello World Example :
program HelloWorld;
uses crt,
Here the main program block starts )
begin writeln ('Hello, World!');
Readkey
end
6. begin and end statements are the main program block.
The end statement indicating the end of the main program is
followed by a full stop (.)
The lines within ( ..*) will be ignored by the compiler and it has
been put to add a comment in the program.
he statement writeln(Hello, World!'); function in Pascal used to
display Message on the screen.
7. Decision Making In Pascal
• Decision Making In Pascal:
- if - then statement
- if-then-else Statement
- Case Statement
- Case Else Statement
8. Decision Making - if - then statement
Syntax for if-then statement is:
if BooleanExpression then
StatementIfTrue;
If the Boolean expression evaluates to true, the statement executes.
Otherwise, it is skipped.
9. program 1fChecking;
var a:integer;
begin a:= 5;
(* check the boolean condition using if statement ) if ( a < 10 ) then
( if condition is true then print the following *) writeln ('a is less than 10
' );
writen value of a is •
a);
end.
10. Decision Making - if - then-else statement
Syntax for the if-then-else statement is:
if BooleanExpression then
StatementIfTrue
else
StatementIfFalse;
If the Boolean expression evaluates to FALSE, the statement following the else will be performed.
program irelseChecking;
var
a : integer:
begin
a := 100;
check the condition )
if 8 < 20 then
( if condition is true then print the following )
writeln ('a is less than 201 )
else ( if condition is false then print the following *)
write n a is not less than 20°
writeln ('value of a is :
", a);
11. Decision Making - case - else of statement
The syntax of the case statement is:
case (expression) of
L1: S1;
Ln: Sn;
end;
Similar to the if-then -else statement .
Easier to read and understand.
Does not accept String variables.
12. Loop in pascal :
Loop in pascal
_ while- do
_for-do
_ repeat until
13. while- do loop
The syntax of a while-do loop is :
While ‹condition> do
begin
The computer will do something;
end;
Where condition is a Boolean or relational expression, whose
value would be true or false and the computer will do something is
a simple statement or group of statements within begin ... end
block.
14. program Whileloop
MAY
x: integer:
begin
while loop will start from one
while
x<do twhile
nOt
begin
11 y mod 2 = 0 then
condition to
write (x, ' "):
Kara increment o
end: ('end of while loor
end
Output
15. : FOR-DO LOOP
• The syntax of for-do loop as follows:
for low to high do begin
The computer will do something;
end:
for high downto low do begin
The computer will do something;
end:
program Forloop;
TalL
x: integer;
begin begin
write (x,' ');
end;
for x:=1 to 10 do (*this mean x is less than or equal 10*)
end
16. REPEAT UNTIL LOOP
Unlike for and while loops, which test the loop condition at the top of the
loop, the repeat ... until loop in Pascal checks its condition at the bottom of
the loop.
The syntax of the repeat until as follows:
repeat
The computer will do something; until<condition›;
Program RepeatUntil;
x:intederi begin
(* repeat until loop execution )
repeat
writex.
X-X+
until y = 11:
"):
end.