Pseudocode - Handout - 2023-24 - Grade 8
Pseudocode - Handout - 2023-24 - Grade 8
2023-2024
Data Types
The following keywords are used to designate data types:
• INTEGER: A whole number
• REAL: A number capable of containing a fractional part
• CHAR: A single character
• STRING: A sequence of zero or more characters
• BOOLEAN: The logical values TRUE and FALSE
Variables
Variables hold values that can be modified when a program is executed
Constants
Constants hold values that remain unchanged when a program is executed.
Identifiers
Identifiers are the names given to variables, and constants. They can only contain letters (A–Z, a–z) and
digits (0–9). Keywords should never be used as variables.
Declaring variables
Variables are declared before we use them in pseudocode. This is to define the data type of the variable.
DECLARE <variable name> : <data type>
Handout
2023-2024
Assignments
The assignment operator is ←.
Assignments should be made in the following format:
<identifier> ← <value>
Example – assignments
Counter ← 0
Counter ← Counter + 1
TotalToPay ← NumberOfHours * HourlyRate
Input
Values are input using the INPUT command as follows:
INPUT <identifier>
The identifier should be a variable.
Output
Values are output using the OUTPUT command as follows:
OUTPUT <value(s)>
Several values, separated by commas, can be output using the same command.
Arithmetic Operators
Standard arithmetic operator symbols are used:
• + Addition
• - Subtraction
• * Multiplication
• / Division
MOD - used to find the remainder
DIV - used to find the quotient
Logic operators
The only logic operators (also called relational operators) used are AND, OR and NOT. The operands
and results of these operations are always of data type BOOLEAN.
Selection statements: IF statements
IF statements may or may not have an ELSE clause.
If-ELSEIF-ELSE conditions
IF<condition> THEN
<statements>
ELSE IF <condition> THEN
<statements>
ELSE IF <condition> THEN
<statements>
.
.
ELSE
<statements>
ENDIF
Multiple If conditions
IF<condition> THEN
<statements>
IF <condition> THEN
<statements>
IF <condition> THEN
<statements>
.
.
ENDIF
Handout
2023-2024
Nested IF conditions
IF <condition> THEN
IF <condition> THEN
<statements>
ELSE
<statements>
END IF
ELSE
IF <condition> THEN
<statements>
ELSE
<statements>
END IF
END IF
Iteration Statements: