REVISION GUIDE · IGCSE 0478 AND A LEVEL 9618

How to write pseudocode in Cambridge exams

The Cambridge pseudocode style for Paper 2: assignment, selection, loops, arrays, procedures and functions, a fully worked exam answer and the mistakes that cost marks.

Pseudocode questions are worth a big share of the marks in Cambridge IGCSE Computer Science (0478) Paper 2 and AS and A Level Computer Science (9618) Paper 2. Examiners give credit for correct logic, but answers written in clear, consistent Cambridge style are far easier to mark, and they leave no doubt about what you meant. This guide shows the keywords you need, the mistakes that cost marks, and a fully worked exam-style answer.

Good news: you are not marked on perfect syntax. A small slip such as a missing ENDIF is usually forgiven if your logic is clear. But writing in the expected style makes your logic clear, so it is worth practising.

1. Variables, constants and assignment

Cambridge pseudocode uses a left arrow for assignment. Read it as “becomes”. Declare variables with their data type, and use constants for values that never change while the program runs.

DECLARE Total : INTEGER
DECLARE Name : STRING
CONSTANT VatRate ← 0.2
Total ← 0
Total ← Total + 5

The data types you need are INTEGER, REAL, CHAR, STRING and BOOLEAN (A Level also uses DATE). Choose meaningful identifiers such as HighestMark rather than x. Examiners and your future self will thank you.

2. Input and output

OUTPUT "Enter your age"
INPUT Age
OUTPUT "You are ", Age, " years old"

Always show a prompt before an INPUT when the question involves a user. It is good practice and sometimes a mark point.

3. Selection: IF and CASE

IF Mark >= 50
   THEN
      OUTPUT "Pass"
   ELSE
      OUTPUT "Fail"
ENDIF

Use CASE when one variable is compared against several fixed values:

CASE OF Choice
   1 : OUTPUT "Start"
   2 : OUTPUT "Settings"
   3 : OUTPUT "Quit"
   OTHERWISE : OUTPUT "Invalid choice"
ENDCASE

The comparison operators are =, <, >, <=, >= and <> (not equal). The logical operators are AND, OR and NOT.

4. Iteration: choosing the right loop

LoopUse it whenExample
FOR … NEXTYou know how many times to repeatRead 30 marks
WHILE … ENDWHILEThe condition is checked first; the loop may run zero timesRead until the user types -1
REPEAT … UNTILThe loop must run at least onceValidation: ask again until the input is valid
FOR Count ← 1 TO 30
   INPUT Mark
   Total ← Total + Mark
NEXT Count

REPEAT
   OUTPUT "Enter a mark from 0 to 100"
   INPUT Mark
UNTIL Mark >= 0 AND Mark <= 100

A very common question asks why a particular loop was chosen. For REPEAT used in validation, the answer is: the input must be taken at least once, and the loop keeps asking until a valid value is entered.

5. Arrays

DECLARE Scores : ARRAY[1:30] OF INTEGER
DECLARE Grid : ARRAY[1:3, 1:3] OF CHAR
Scores[1] ← 72
Grid[2, 3] ← "X"

Always state the bounds and the data type. Use a FOR loop to process every element, with the loop counter as the index.

6. Procedures and functions

A procedure carries out a task. A function returns a single value, so its header states the return type.

PROCEDURE ShowLine(Length : INTEGER)
   FOR i ← 1 TO Length
      OUTPUT "-"
   NEXT i
ENDPROCEDURE

FUNCTION Square(Num : INTEGER) RETURNS INTEGER
   RETURN Num * Num
ENDFUNCTION

CALL ShowLine(20)
Answer ← Square(7)

Notice that a procedure is run with CALL, while a function is used inside an expression. Using parameters, rather than global variables, shows good practice and is often rewarded at A Level.

7. Strings and built-in functions

You will often need the length of a string, part of a string (a substring), or a string changed to upper or lower case. The exact function names you can use are given in the question or in the Cambridge pseudocode guide for your syllabus, so learn the ones listed for 0478 or 9618 and use them exactly as shown. If you are unsure, write a short comment explaining what your line does: the examiner is looking for correct logic.

8. Worked example

Question: Write an algorithm that inputs 10 marks. Each mark must be from 0 to 100. Output the highest mark and the average mark. [8]

DECLARE Mark, Highest, Total, Count : INTEGER
DECLARE Average : REAL
Highest ← -1
Total ← 0
FOR Count ← 1 TO 10
   REPEAT
      OUTPUT "Enter mark ", Count
      INPUT Mark
   UNTIL Mark >= 0 AND Mark <= 100
   Total ← Total + Mark
   IF Mark > Highest
      THEN
         Highest ← Mark
   ENDIF
NEXT Count
Average ← Total / 10
OUTPUT "Highest mark: ", Highest
OUTPUT "Average mark: ", Average

Where the marks come from:

  • Initialising Total and Highest before the loop.
  • A loop that runs 10 times.
  • Input with a prompt, inside the loop.
  • Validation that repeats until the mark is from 0 to 100.
  • Adding each mark to the running total.
  • Comparing with the highest so far and updating it.
  • Calculating the average after the loop.
  • Outputting both results with messages.

9. Mistakes that cost marks

  • Forgetting to initialise a total or counter before the loop.
  • Calculating the average inside the loop instead of after it.
  • Using = for assignment instead of ←, which makes your meaning unclear.
  • Writing Python or Java syntax, such as for i in range(10):. Pseudocode questions expect pseudocode.
  • Missing the requirement hidden in the question, such as validation or a final message. Tick off every requirement as you write.
  • Off-by-one loops: FOR Count ← 0 TO 10 runs 11 times, not 10.
Exam habit: before you start, underline every requirement in the question. When you finish, check each one is in your answer. Most lost marks are missed requirements, not wrong syntax.

10. Practise it

Run your own pseudocode in the Coding Lab, which follows Cambridge style, and check it against the questions on the IGCSE Programming and A Level Programming units. For the longest question on IGCSE Paper 2, read How to answer the 15-mark scenario question.

Frequently asked questions

Do I lose marks for small syntax errors in pseudocode?

Usually not. Examiners mark the logic, so a missing ENDIF or a slightly different keyword is normally accepted if your meaning is clear. Clear, consistent style helps make sure it is.

Is IGCSE pseudocode the same as A Level pseudocode?

The style is the same, with the same keywords for assignment, selection, loops, arrays and subroutines. A Level adds more, such as records, file handling modes and object-oriented features, and its list of built-in functions is longer.

Can I write Python instead of pseudocode?

Only when the question asks for program code. If a question asks for pseudocode, write pseudocode.

Want help with programming questions? In a 1-to-1 lesson we can work through past-paper algorithms together. Book a free demo →

Was this page helpful?