Handout
2023-2024
Name: Subject: Computer Science
Grade: Topic: Pseudocode
Date:
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.
Example of Input and Output Statements
INPUT Answer
OUTPUT Score
OUTPUT “You have” , Lives , “lives left”
*In the above example: Answer, Score, Lives are variable names
Handout
2023-2024
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 statements without an else clause are written as follows:
IF <condition> THEN
<statements>
END IF
IF statements with an ELSE clause are written as follows:
IF <condition> THEN
<statements>
ELSE
<statements>
END IF
Handout
2023-2024
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:
WHILE LOOP (Pre-condition loops)
Pre-condition loops are written as follows:
WHILE <condition> DO
<statements>
END WHILE
The condition must be an expression that evaluates to a Boolean.
The condition is tested before the statements, and the statements will only be executed if the condition
evaluates to TRUE. After the statements have been executed the condition is tested again. The loop
terminates when the condition evaluates to FALSE.
The statements will not be executed if, on the first test, the condition evaluates to FALSE.