Pascal Programming
Program Outline
{Author:
Date: COMMENTS
Description:
PROGRAM name_of_program; PROGRAM HEAD
USES
CRT;
CONST DECLARATION
VAR
BEGIN
STATEMENTS; BODY/ PROGRAM MAIN
END .
1
COMPARISON OF CODES
CODE TYPE PSEUDOCODE PASCAL
Constant Constant Const
Pi3.14 Pi=3.14;
Declare Variables Declare VAR
Num1, num2, num3 AS INTEGER Num1, num2 : Integer;
Array declaration DECLARE VAR
ARRAY name[5] AS STRING name: Array[1..5] OF STRING;
Initialization Sum 0 Begin
Sum:=0;
END.
Output PRINT” hello world” BEGIN
WRITELN(‘Hello world’);
WRITE (‘Hello world’);
END.
Input READ num BEGIN
READLN (num);
READ (num);
END.
Assignment Sumnum1+ num2 BEGIN
Sum:= num1+num2 ;
END.
BEGIN
FOR loop FOR counter ← 1 TO 10 DO FOR counter := 1 TO 10 DO
PRINT "Hello world!" WRITELN ('Hello world!');
ENDFOR END.
When there are multiple lines in
the construct, they are placed
between a begin and end;
BEGIN
FOR counter := 1 TO 10 DO
BEGIN
WRITELN ('Hello world!');
WRITELN ('Hello world2!');
END; //end of loop
END.
2
BEGIN
WHILE loop WHILE num <> 0 DO WHILE num <> 0 DO
sum ← sum + num sum := sum + num;
ENDWHILE END.
When there are multiple lines in
the construct, they are placed
between a begin and end;
BEGIN
REPEAT UNTIL REPEAT REPEAT
PRINT "Hello World" WRITELN ('Hello World');
X ← X +1 X := X + 1;
UNTIL X > 5 UNTIL X > 5;
END.
IF-THEN IF A > B THEN BEGIN
PRINT A IF A > B THEN
ENDIF WRITELN (B);
END.
When there are multiple lines in
the construct, they are placed
between a begin and end;
IF-THEN-ELSE IF A > B THEN BEGIN
PRINT A IF A >B THEN
ELSE WRITELN (A)
PRINT B ELSE
ENDIF WRITELN (B);
END.
NB. NO semi-colon before an
ELSE
When there are multiple lines in
the construct, they are placed
between a begin and end;
3
BEGIN
NESTED IF-THEN-ELSE IF age <= 3 THEN IF age <= 3 THEN
PRINT “hi” WRITELN (‘Hi’)
ELSE ELSE
IF age <= 10 THEN IF age <= 10 THEN
PRINT “ hello” WRITELN (‘Hi’)
ELSE ELSE
IF age <= 18 THEN IF age <= 18 THEN
PRINT “No” WRITELN (‘Hi’)
ELSE ELSE
PRINT “Yes” WRITELN (‘Hi’);
ENDIF
ENDIF NB. NO semi-colon before an
ENDIF ELSE
When there are multiple lines in
the construct, they are placed
between a begin and end;
SYMBOL PURPOSE
= Constant assignment or comparison in an if
statement
:= Assignment operator
; Terminates a line
. Terminates the program