IGCSE 0478 Computer Science
Pseudocode
1. Keywords
a) INTEGER: A whole number
b) REAL: A number capable of containing fractional part
c) CHAR: A single character
d) STRING: A sequence of zero or more characters
e) BOOLEAN: The logical values of True and False
2. Arrays
Arrays are fixed-length lists that store items of the same type. Each item is accessible using an
index number.
Example-
StudentNames[1] “Ali”
NoughtsAndCrosses[2] ‘X’
3. Input and output
Values are input using the Input command and, are output using the Output command.
Example-
Input Answer
Output Score
Output “You have ”, Lives, “ lives left”
4. Arithmetic operations
a) + Addition
b) – Subtraction
c) * Multiplication
d) / Division
5. IF statements
IF may or may not have an ELSE clause.
Format (without an ELSE clause)-
IF <condition>
THEN
<statements>
ENDIF
Format (with an ELSE clause)-
IF <condition>
THEN
<statements>
ELSE
<statements>
ENDIF
6. CASE statements
CASE statements allow one out of several branches of code to be executed, depending on the
value of a variable.
Format-
CASE OF <identifier>
<value 1> : <statement>
<value 2> : <statement>
...
ENDCASE
Format (with an OTHERWISE clause)-
CASE OF <identifier>
<value 1> : statement
<value 2> : statement
...
OTHERWISE <statement>
ENDCASE
Example (formatted CASE statement)-
INPUT Move
CASE OF Move
‘W’ : Position Position – 10
‘S’ : Position Position + 10
‘A’ : Position Position – 1
‘D’ : Position Position + 1
OTHERWISE : Beep
ENDCASE
7. Count-controlled (FOR) loops
Format-
FOR <identifier> <value1> TO <value2>
<statements>
NEXT
The identifier must be of data type INTEGER.
Example (nested FOR loops)-
Total = 0
FOR Row = 1 TO MaxRow
RowTotal = 0
FOR Column = 1 TO 10
RowTotal RowTotal + Amount[Row, Column]
NEXT Column
OUTPUT “Total for Row “, Row, “ is ”, RowTotal
Total Total + RowTotal
Next ROW
OUTPUT “The grand total is “, Total
8. Post-condition (REPEAT UNTIL) loops
Format-
REPEAT
<statements>
UNTIL <condition>
Example (REPEAT UNTIL statement)-
REPEAT
OUTPUT “Please enter a password”
INPUT Password
UNTIL Password = “Secret”
9. Pre-condition (WHILE) loops
Format-
WHILE (condition) DO
<statements>
ENDWHILE
Example (WHILE loop)-
WHILE Number > 9 DO
Number Number – 9
ENDWHILE