Professional Documents
Culture Documents
IT-F5 - Notes - Pseudocode Basics
IT-F5 - Notes - Pseudocode Basics
Topic: PSEUDOCODE
Types of Pseudocoding:
• SEQUENTIAL
• CONDITIONAL
o IF-THEN
o IF-THEN-ELSE
o NESTED CONDITION
• LOOPS
o WHILE or REPEAT
o FOR
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.
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
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
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.
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
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