CASE OF variable
Condition : Statement
Condition : Statement
Condition : Statement
Condition : Statement
Condition : Statement
OTHERWISE Statement
ENDCASE
U for Up
L for Left
R for Right
D for Down
DECLARE Choice : CHAR
OUTPUT “Enter your choice U for up, L for left, R for right and D
for down. ”
INPUT Choice
CASE OF Choice
‘U’ : OUTPUT “Move up”
‘L’ : OUTPUT “Move left”
‘R’ : OUTPUT “Move right”
‘D’ : OUTPUT “Move down”
OTHERWISE “Invalid move. ”
ENDCASE
PROCEDRUE / FUNCTIONS:
Sub-Routines: It is not a complete program but a named
section of a code, that performs specific task in the program. It
can be defined and used with or without parameters.
Procedures never return any value to the main program and
Functions always return a value to the program.
Parameters are the arguments (values) provided to the sub-
routine when it is called.
Procedure Definition:
PROCEDRUE <identifier> (parameter : data type)
Statement/s
ENDPROCEDURE
Procedure Call:
CALL identifier (parameter)
Function Definition:
FUNCTION <identifier> (parameter: data type) RETURNS datatype
Statement/s
RETURN value
ENDFUNCTION
Function Call:
Variable identifier (parameter)
Q: Write a procedure “Add” that inputs 2 integer values and
displays their total.
PROCEDRUE Add ()
DECLARE Value1, Value2 : INTEGER
INPUT Value1
INPUT Value2
OUTPUT Value1+Value2
ENDPROCEDURE
CALL Add ()
Q: Write a procedure “Add” that is called with 2 integer values and
displays their total.
PROCEDRUE Add (Num1, Num2 : INTEGER)
OUTPUT Value1+Value2
ENDPROCEDURE
CALL Add (7, 5)
Q: Write a Function AverageSpeed that inputs time and distance
and returns the average speed.
FUNCTION AverageSpeed () RETURNS REAL
DECLARE Time : INTEGER
DECLARE Distance : INTEGER
OUTPUT “Enter time. ”
INPUT Time
OUTPUT “Enter distance. ”
INPUT Distance
RETURN (Distance/Time)
ENDFUNCTION
IF AverageSpeed () > 100
THEN
OUTPUT “Too fast”
ELSE
OUTPUT “Too slow. ”
ENDIF
FUNCTION CheckDiscount (Age: INTEGER) RETURNS INTEGER
DECLARE Per : INTEGER
IF (Age >= 5 AND Age <= 12) OR (Age > 50)
THEN
RETURN 10
ELSE
IF Age >= 13 AND Age <=19
THEN
RETURN 7
ELSE
RETURN 0
ENDIF
ENDIF
ENDFUNCTION
PROCEDURE CheckBill (amount: REAL)
DECLARE Age, Percentage : INTEGER
DECLARE DiscAmount, NetBill : REAL
OUTPUT “Enter age. ”
INPUT Age
Percentage CheckDiscount(Age)
DiscAmount (amount * Percentage) / 100
NetBill Amount – DiscAmount
OUTPUT “Amount: ”, Amount
OUTPUT “Discount Percent: ”, Percentage, “%”
OUTPUT “Discounted Amount: ”, DiscAmount
OUTPUT “Net Bill: ”, NetBill
ENDPROCEDURE