Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

DARUL ULOOM TRINIDAD AND TOBAGO LIMITED

INFORMATION TECHNOLOGY – FORM 5

Topic: PSEUDOCODE

Types of Pseudocoding:

• SEQUENTIAL
• CONDITIONAL
o IF-THEN
o IF-THEN-ELSE
o NESTED CONDITION
• LOOPS
o WHILE or REPEAT
o FOR

Common Command Keywords to indicate Input, Output and Processing


Input: READ, OBTAIN, GET
Output: PRINT, DISPLAY, SHOW
Compute: COMPUTE, CALCULATE, DETERMINE

Initialize: SET, INIT


Add One: INCREMENT, BUMP

SEQUENTIAL Codes are exactly that. They are a sequence of commands/processes to be


carried out, in order of listing, 1 at a time, from start to end.
Example:
Program: Add_Three_Numbers
DISPLAY “Please Input Number 1”
GET number1
DISPLAY “Please Input Number 2”
GET number2
DISPLAY “Please Input Number 3”
GET number3
sum = number1 + number2 + number3
DISPLAY sum
END

Prepared By: Farook Mohammed Jr.


Page 1 | 5
DARUL ULOOM TRINIDAD AND TOBAGO LIMITED
INFORMATION TECHNOLOGY – FORM 5

CONDITIONAL Codes are exactly that. They are used when there are choices or multiple
conditions to be examined/executed. For this we generally use IF-THEN and IF-THEN-ELSE
statements.

IF-THEN Statement is used when 1 or more statements will be considered based on a


condition or answer to process. This statement will only execute if the condition is TRUE.
It is written as: IF condition is true
THEN carry out process
ENDIF

Example:

Program: Add_Three_Numbers_But_Output_Sum_If_More_Than_50
DISPLAY “Please Input Number 1”
GET number1
DISPLAY “Please Input Number 2”
GET number2
DISPLAY “Please Input Number 3”
GET number3
sum = number1 + number2 + number3
IF sum >50
THEN DISPLAY sum
ENDIF
END

Prepared By: Farook Mohammed Jr.


Page 2 | 5
DARUL ULOOM TRINIDAD AND TOBAGO LIMITED
INFORMATION TECHNOLOGY – FORM 5

IF-THEN-ELSE Statement is used when you have multiple outcomes based on an execution. If
the result is TRUE then Process A occurs, while if it is FALSE, then Process B occurs.
It is written as: IF condition is true
THEN carry out process a
ELSE carry out process b
ENDIF

Example:
Program: Add_Three_Numbers
DISPLAY “Please Input 3 Numbers”
GET number1, number2, number3
sum = number1 + number2 + number3
IF sum >50
THEN DISPLAY “Your Total is More Than 50. It is”, sum
ELSE DISPLAY “Your Total is Less Than 50. It is”, sum
ENDIF
END

NESTED CONDITION Statement is used when there are multiple uses of IF-THEN and/or IF-
THEN-ELSE statements, together or separately.

Example:
Program: Body_Temperature
GET temp
IF temp >38
THEN DISPLAY “Your Temperature is TOO HIGH. You are sick!”
DISPLAY “Kindly go home.”
ELSE IF temp <38
THEN DISPLAY “Your Temperature is GOOD. You are well!”
DISPLAY “Kindly go to class.”
DISPLAY “Please record your temperature in your log. Thank you.
ENDIF
END

Prepared By: Farook Mohammed Jr.


Page 3 | 5
DARUL ULOOM TRINIDAD AND TOBAGO LIMITED
INFORMATION TECHNOLOGY – FORM 5

LOOP Codes are exactly that. A Loop is used when you need to cycle through a process or
series of processes until there is a specific outcome. With loops, there are two types which
are used, WHILE or REPEAT and FOR.

WHILE (REPEAT) LOOP


This loop is also known as an Indefinite Loop because it is used when the amount of loop
cycles is unknown. The WHILE loop cycles through one or more statements repeatedly so
long as the condition is TRUE. Keep in mind that the condition being tested is at the
beginning of this loop and it is possible that the loop can be unexecuted. However, the
REPEAT loop cycles through one or more statements repeatedly so long as the condition is
FALSE. Keep in mind that the condition being tested is at the end of this loop and it will
always be executed, at least once.
The WHILE Loop is written as: WHILE condition is true
statement(s) [Note the indent]
ENDWHILE

The REPEAT Loop is written as: REPEAT


statement(s) [Note the indent]
UNTIL condition is true
Example:
Program: Calculate_Population
GET population
DISPLAY “Your Input Population Amount Is”, population
WHILE population < limit
BEGIN
COMPUTE population as population + births - deaths
ENDWHILE
DISPLAY “Your New Population Is”, population
END

Program: Counting_To_12
SET counter=1
REPEAT
counter = counter + 1
DISPLAY “The Count Is”, counter
UNTIL counter = 12
DISPLAY “The Count Is More Than 12”
END

Prepared By: Farook Mohammed Jr.


Page 4 | 5
DARUL ULOOM TRINIDAD AND TOBAGO LIMITED
INFORMATION TECHNOLOGY – FORM 5

FOR LOOP
This loop is also known as a Definite Loop because it is used when the amount of loop cycles
is known in advance.
It is written as: FOR variable.startvalue TO/DOWNTO variable.endvalue DO
statement(s) [Note the indent of the statement(s)]
ENDFOR

Example:

Program: Countdown_To_0
DISPLAY “Please Input Starting Number”
GET number
FOR countdown = number DOWNTO 0
OUTPUT countdown
ENDFOR
OUTPUT “The countdown has ended. Nothing else to count.”
END

Program: Counting_To_100
DISPLAY “Please Input Starting Number”
GET number
FOR count = number+1 TO 100
OUTPUT count
ENDFOR
OUTPUT “The count has passed 100. Cannot continue.”
END

Prepared By: Farook Mohammed Jr.


Page 5 | 5

You might also like