Pseudocode 伪代码 is a way to write an algorithm 算法 that looks like a program but is not tied to one programming language. In the 9618 exam, every algorithm in a question is printed in pseudocode, and many answers must be written in it. Cambridge publishes one guide that sets the rules, and this reference follows it.
You do not need perfect pseudocode to get the marks. You do need pseudocode that a marker can read without guessing. The rules below make that easy.
Keywords are in capitals
A keyword 关键字 is a word with a fixed meaning, such as IF, WHILE, DECLARE or
OUTPUT. Keywords are always written in upper case upper case 大写.
DECLARE Total : INTEGER
Total ← 10 + 5
OUTPUT Total
Here DECLARE, INTEGER and OUTPUT are keywords. Total is a name that we chose.
Identifiers
An identifier 标识符 is the name you give to a variable, a constant, a procedure or a function. The 9618 rules are:
- It starts with a letter (A–Z or a–z), never a digit.
- After the first letter it may contain letters, digits (0–9) and the underscore
_. - No spaces, no accented letters, and no other symbols.
- It must not be a keyword.
OutputorCasecannot be a variable name.
| Identifier | Allowed? | Why |
|---|---|---|
TotalScore |
yes | letters only |
Player2 |
yes | a digit after the first letter is fine |
max_value |
yes | 9618 allows the underscore and a small first letter |
2ndPlace |
no | starts with a digit |
Total Score |
no | contains a space |
WHILE |
no | it is a keyword |
Cambridge writes identifiers in mixed case mixed case 混合大小写: each new word starts
with a capital, as in NumberOfPlayers. This is the style you will see in every paper.
Choose names that explain themselves
Good names make your answer easier to mark. Average says what the value means; A does
not. Single letters are fine only where they are a normal habit: i and j for array
indices, X and Y for coordinates.
Identifiers are case-insensitive
Count, COUNT and count are treated as the same name. So never use two names that
differ only in case, such as CountDown and Countdown. A marker will see one variable, and
your algorithm will not mean what you wanted.
DECLARE Count : INTEGER
Count ← 3
count ← count + 1
OUTPUT COUNT
This prints 4: all three spellings reach one variable. It runs, but it is bad style. Pick
one spelling and keep it.
Common mistakes
- Writing keywords in small letters, such as
iforoutput. WriteIFandOUTPUT. - Using a keyword as a name, for example
DECLARE String : STRING. - Putting a space inside a name: write
FirstName, notFirst Name.
![Scores[1:5]: five boxes, one name, each reached by its index](/handout-media/ref_as_pseudocode/assets/06-array-1d.png?v=1795261552)
![Board[1:3, 1:3]: the first index picks the row, the second the column](/handout-media/ref_as_pseudocode/assets/06-array-2d.png?v=1795261552)