OCR GCSE Computer Science: Pseudocode Reference Language Cheat Sheet
OCR GCSE Computer Science: Pseudocode Reference Language Cheat Sheet
OCR GCSE Computer Science (J277) uses a prescribed pseudocode syntax called the Exam Reference Language (ERL). In the exam, you will be asked to read, trace, and write code using this syntax. While it looks similar to Python, there are important differences that can cost you marks if you get them wrong.
This guide covers every part of the OCR pseudocode syntax you need to know, compares each construct with its Python equivalent, highlights the traps that catch students out, and gives you exercises to practise.
Variables and Data Types
In OCR pseudocode, you do not need to declare variable types. You simply assign a value, and the data type is inferred from the value assigned.
OCR Pseudocode:
name = "Alice"
age = 16
score = 85.5
passed = true
Python equivalent:
name = "Alice"
age = 16
score = 85.5
passed = True
The key difference: OCR pseudocode uses lowercase true and false for Boolean values, while Python uses capitalised True and False.
Common Data Types
| Data Type | Example in OCR Pseudocode | Description |
|---|---|---|
| Integer | count = 10 | Whole numbers |
| Real (float) | price = 4.99 | Decimal numbers |
| Boolean | found = false | true or false |
| Character | letter = 'A' | A single character |
| String | word = "Hello" | A sequence of characters |
Casting (Type Conversion)
OCR pseudocode uses casting functions to convert between types:
str(42) // converts integer 42 to string "42"
int("42") // converts string "42" to integer 42
float("3.14") // converts string "3.14" to real 3.14
bool("true") // converts string to Boolean
Python equivalent:
str(42)
int("42")
float("3.14")
# Python does not have a direct bool("true") equivalent
Input and Output
OCR Pseudocode:
name = input("Enter your name: ")
print("Hello " + name)
Python equivalent:
name = input("Enter your name: ")
print("Hello " + name)
These are identical in both languages. Note that input() in OCR pseudocode always returns a string, just as it does in Python. If you need a number, you must cast it:
age = int(input("Enter your age: "))
Arithmetic and Comparison Operators
Arithmetic Operators
| Operator | Meaning | OCR Example | Python Equivalent |
|---|---|---|---|
+ | Addition | x = 5 + 3 | x = 5 + 3 |
- | Subtraction | x = 10 - 4 | x = 10 - 4 |
* | Multiplication | x = 6 * 7 | x = 6 * 7 |
/ | Division | x = 20 / 4 | x = 20 / 4 |
MOD | Modulus (remainder) | x = 10 MOD 3 | x = 10 % 3 |
DIV | Integer division | x = 10 DIV 3 | x = 10 // 3 |
^ | Exponentiation | x = 2 ^ 3 | x = 2 ** 3 |
Pay close attention to MOD and DIV -- OCR uses words rather than symbols. 10 MOD 3 gives 1 (the remainder). 10 DIV 3 gives 3 (integer division, discarding the remainder).
Comparison Operators
| Operator | Meaning |
|---|---|
== | Equal to |
!= | Not equal to |
< | Less than |
> | Greater than |
<= | Less than or equal to |
>= | Greater than or equal to |
Critical distinction: = is used for assignment (giving a variable a value). == is used for comparison (checking if two values are equal). Confusing these is one of the most common mistakes in the exam.
score = 50 // assignment: score is now 50
if score == 50 // comparison: is score equal to 50?
Boolean Operators
OCR pseudocode uses AND, OR, and NOT:
if age >= 18 AND hasTicket == true then
print("Entry allowed")
endif
Python equivalent:
if age >= 18 and hasTicket == True:
print("Entry allowed")
Selection (If / Elseif / Else / Switch)
If Statements
OCR Pseudocode:
if score >= 50 then
print("Pass")
elseif score >= 40 then
print("Near miss")
else
print("Fail")
endif
Python equivalent:
if score >= 50:
print("Pass")
elif score >= 40:
print("Near miss")
else:
print("Fail")
Key differences from Python:
- OCR uses
thenafter the condition - OCR uses
elseif(one word), Python useselif - OCR requires
endifto close the block -- Python uses indentation alone - Forgetting
endifis one of the most common mark-losing mistakes in the exam
Switch / Case Statements
OCR Pseudocode:
switch day:
case "Monday":
print("Start of the week")
case "Friday":
print("Nearly the weekend")
default:
print("Midweek")
endswitch
Python equivalent:
Python 3.10+ has match/case, but for GCSE purposes, the equivalent is typically an if/elif/else chain:
if day == "Monday":
print("Start of the week")
elif day == "Friday":
print("Nearly the weekend")
else:
print("Midweek")
Remember to close with endswitch.
Iteration (Loops)
OCR pseudocode has three types of loop. You must know when to use each one.
FOR Loop (Count-Controlled)
Use when you know in advance how many times the loop should run.
OCR Pseudocode:
for i = 0 to 4
print(i)
next i
This prints: 0, 1, 2, 3, 4 (five values -- the range is inclusive of both ends).
Python equivalent:
for i in range(5):
print(i)
Important difference: OCR's for i = 0 to 4 includes 4. Python's range(5) goes from 0 to 4 as well, but if you wrote range(4) thinking it matched 0 to 4, you would only get 0, 1, 2, 3. The OCR range is inclusive on both ends.
You can also use a step value:
for i = 0 to 10 step 2
print(i)
next i
This prints: 0, 2, 4, 6, 8, 10.
WHILE Loop (Condition-Controlled, Pre-Check)
Use when the loop should keep running as long as a condition is true. The condition is checked before each iteration, so the loop body may never execute if the condition is false from the start.
OCR Pseudocode:
while answer != "yes"
answer = input("Continue? ")
endwhile
Python equivalent:
while answer != "yes":
answer = input("Continue? ")
Close with endwhile in OCR pseudocode.
DO...UNTIL Loop (Condition-Controlled, Post-Check)
Use when the loop body must execute at least once. The condition is checked after each iteration.
OCR Pseudocode:
do
password = input("Enter password: ")
until password == "secret123"
Python equivalent (no direct equivalent):
while True:
password = input("Enter password: ")
if password == "secret123":
break
Python does not have a native do...until loop, which is why OCR students sometimes forget this structure exists. In the exam, if a question requires a loop that must run at least once, a do...until loop is usually the cleanest answer.
Arrays
OCR Pseudocode:
array names[5]
names[0] = "Alice"
names[1] = "Bob"
names[2] = "Charlie"
print(names[0])
Python equivalent:
names = [""] * 5
names[0] = "Alice"
names[1] = "Bob"
names[2] = "Charlie"
print(names[0])
Key points:
- OCR arrays are zero-indexed (the first element is at index 0)
- You declare an array with
array variableName[size] - Accessing an index outside the array bounds would cause an error
Two-Dimensional Arrays
array grid[3,3]
grid[0,0] = "X"
grid[1,1] = "O"
Python equivalent:
grid = [["" for _ in range(3)] for _ in range(3)]
grid[0][0] = "X"
grid[1][1] = "O"
In OCR pseudocode, 2D array elements are accessed with grid[row,col] (comma-separated within one set of brackets), whereas Python uses grid[row][col] (two sets of brackets).
String Operations
OCR pseudocode includes built-in string functions:
| Function | Purpose | Example | Result |
|---|---|---|---|
stringName.length | Returns the length of the string | "Hello".length | 5 |
stringName.substring(start, length) | Extracts part of a string | "Hello".substring(1,3) | "ell" |
stringName.upper | Converts to uppercase | "hello".upper | "HELLO" |
stringName.lower | Converts to lowercase | "HELLO".lower | "hello" |
ASC(character) | Returns ASCII value | ASC("A") | 65 |
CHR(integer) | Returns character from ASCII value | CHR(65) | "A" |
Python equivalents:
len("Hello") # 5
"Hello"[1:4] # "ell"
"hello".upper() # "HELLO"
"HELLO".lower() # "hello"
ord("A") # 65
chr(65) # "A"
Note the differences: OCR uses .length (a property), Python uses len() (a function). OCR's .substring(1,3) takes a start position and a length, while Python's slice [1:4] takes a start and end position. This catches many students out.
File Handling
OCR pseudocode includes file operations:
Reading from a file:
myFile = openRead("data.txt")
line1 = myFile.readLine()
myFile.close()
Writing to a file:
myFile = openWrite("output.txt")
myFile.writeLine("Hello, World!")
myFile.close()
Python equivalents:
# Reading
myFile = open("data.txt", "r")
line1 = myFile.readline()
myFile.close()
# Writing
myFile = open("output.txt", "w")
myFile.write("Hello, World!\n")
myFile.close()
You can also check for the end of a file using endOfFile():
myFile = openRead("data.txt")
while NOT myFile.endOfFile()
print(myFile.readLine())
endwhile
myFile.close()
Always remember to close files after use.
Subroutines: Functions and Procedures
OCR distinguishes between functions (which return a value) and procedures (which do not).
Functions
function calculateArea(length, width)
area = length * width
return area
endfunction
// Calling the function:
result = calculateArea(5, 3)
print(result)
Procedures
procedure displayMessage(name)
print("Welcome, " + name + "!")
endprocedure
// Calling the procedure:
displayMessage("Alice")
Python equivalent:
def calculate_area(length, width):
area = length * width
return area
def display_message(name):
print("Welcome, " + name + "!")
Python uses def for both functions and procedures. OCR separates them with function/endfunction and procedure/endprocedure. In the exam, if the question asks you to write a function, make sure you include a return statement. If it asks for a procedure, do not return a value.
Scope: Local and Global Variables
Variables declared inside a subroutine are local -- they only exist within that subroutine. Variables declared outside any subroutine are global -- they can be accessed from anywhere in the program.
global totalScore = 0
procedure addScore(points)
totalScore = totalScore + points
endprocedure
In general, using local variables and passing values through parameters is better practice than relying on global variables. Examiners often ask why -- the answer is that local variables reduce the risk of unintended side effects and make code easier to debug and maintain.
Common Exam Traps
These are the mistakes that examiners report seeing most frequently. Avoid them and you will pick up marks that many students lose.
-
Forgetting
endif,endwhile,endfunction,endprocedure, orendswitch. Every opening keyword must have its matching closing keyword. Get into the habit of writing the closing keyword immediately after the opening one, then filling in the body. -
Using
=instead of==in conditions.=is assignment.==is comparison. Writingif x = 5 thenwhen you meanif x == 5 thenis technically incorrect in OCR pseudocode. -
Array indexing errors. OCR arrays are zero-indexed. An array declared as
array items[5]has valid indices 0, 1, 2, 3, 4. Accessingitems[5]would be out of bounds. -
Confusing
.substring(start, length)with Python slicing."Hello".substring(1, 3)returns"ell"(starting at index 1, taking 3 characters). Python's"Hello"[1:3]returns"el"(from index 1 up to but not including index 3). Different behaviour, same-looking numbers. -
Forgetting
thenafterif. In OCR pseudocode, everyifcondition must be followed bythen. Python does not usethen, so students who code primarily in Python often omit it. -
Writing Python syntax in a pseudocode question. If the question says "using pseudocode" or "using OCR Exam Reference Language," you must use OCR syntax. Writing
elifinstead ofelseif, orrange()instead offor i = 0 to n, will lose marks.
Practice Exercises
Test yourself by tracing through these pseudocode snippets. Work out what each one outputs before checking the answer.
Exercise 1: Trace the Output
x = 5
y = 3
while x > 0
x = x - y
y = y + 1
print(x)
endwhile
Think about it: What values do x and y take on each iteration? When does the loop end? What gets printed?
Iteration 1: x = 5 - 3 = 2, y = 3 + 1 = 4, prints 2 Iteration 2: x = 2 - 4 = -2, y = 4 + 1 = 5, prints -2 Loop ends because x (-2) is not greater than 0.
Output: 2, -2
Exercise 2: What Does This Function Return?
function mystery(word)
result = ""
for i = word.length - 1 to 0 step -1
result = result + word.substring(i, 1)
next i
return result
endfunction
print(mystery("code"))
Think about it: What does the loop do on each iteration? What is the final value of result?
The function reverses the string. Starting from the last character and working backwards, it appends each character to result.
- i = 3: result = "" + "e" = "e"
- i = 2: result = "e" + "d" = "ed"
- i = 1: result = "ed" + "o" = "edo"
- i = 0: result = "edo" + "c" = "edoc"
Output: edoc
Exercise 3: Find the Bug
array scores[5]
scores[0] = 72
scores[1] = 85
scores[2] = 63
scores[3] = 91
scores[4] = 78
total = 0
for i = 1 to 5
total = total + scores[i]
next i
average = total / 5
print(average)
Think about it: There are two bugs. Can you spot them both?
Bug 1: The loop starts at i = 1 instead of i = 0, so it skips scores[0] (which is 72).
Bug 2: The loop goes up to i = 5, but the highest valid index is 4. scores[5] is out of bounds and would cause an error.
Fix: Change for i = 1 to 5 to for i = 0 to 4.
Tips for Writing Pseudocode in the Exam
- Write the structure first, then fill in the detail. If you need a loop, write the
for/nextorwhile/endwhilepair first, then add the body. - Use meaningful variable names.
totalScoreis better thanx. It makes your code easier to follow and shows the examiner you understand good programming practice. - Indent your code. Proper indentation shows the structure of your program and makes it easier for the examiner to follow your logic. It also demonstrates your understanding of maintainability.
- Add comments if they help clarity. You can use
//for comments in OCR pseudocode. A short comment explaining a tricky section can help the examiner give you the benefit of the doubt. - Check your closing keywords. Before moving on from a question, scan your code and match every
ifwith anendif, everywhilewith anendwhile, and everyfunction/procedurewith its closing keyword.
How the Exam Reference Language Is Actually Examined
It helps to understand why OCR insists on a reference language at all, because it changes how you revise. J277 is assessed by two written papers, and the programming skills live in Paper 2 (Computational Thinking, Algorithms and Programming, J277/02), which is worth 80 marks and 50% of the qualification. Because it is a written paper, OCR cannot mark code that only runs in one particular language. A student who learns Python at one school, another who learns C# and a third who learns Visual Basic all have to be marked against a single, consistent standard. The Exam Reference Language solves that problem: it is a neutral, published syntax that every OCR candidate can read regardless of the language they programmed in during the course.
This matters for your revision in three concrete ways.
First, questions come in three flavours, and each rewards a different skill. Some ask you to read and trace ERL code — you follow it line by line and state the output or fill in a trace table. Some ask you to write code, and here OCR allows you to answer in ERL or in a recognised high-level language of your choice, as long as it is consistent and the logic is correct. Some ask you to complete or correct code — a partially written algorithm with a gap or a bug that you finish or fix. You should practise all three, not just writing from scratch, because tracing and debugging are where a lot of the accessible marks sit.
Second, when you write an answer, you are marked on logic first and syntax second. Examiners are trained to reward a correct algorithm even if a keyword is slightly off, so a solution that is logically sound but writes end if instead of endif will usually still earn most of the marks. That said, you should not rely on this. Clean, consistent syntax removes any doubt about your intent, and on the boundary between two marks the benefit of the doubt is worth having. The safe strategy is to learn ERL properly and be fluent in your chosen high-level language, then answer in whichever the question steers you toward.
Third, consistency is assessed. If you start an answer in ERL, finish it in ERL. Mixing elseif (ERL) with elif (Python) in the same answer signals that you have not internalised either language and invites the examiner to read your logic less charitably. Pick a lane at the start of each question and stay in it.
What the reference language does not include
A frequent source of wasted revision is students learning constructs that are not part of the GCSE reference language at all. Keep your preparation tight:
- There is no object-oriented programming at J277 — no classes, no objects, no methods, no inheritance. That is A-Level material (it appears in OCR H446). If you find yourself writing
class Playerin a GCSE answer, you have over-reached. - There is no exception handling (
try/except) in the reference language. Robustness at GCSE is achieved through input validation and defensive design, nottry/catchblocks. - Records and complex data structures such as stacks and queues as named structures are A-Level topics. At GCSE you work with variables, constants and one- or two-dimensional arrays — that is the full toolkit, and it is enough to answer every J277 programming question.
Revising the right scope is as important as revising hard. Everything in this cheat sheet is in scope; nothing beyond it is required.
A Fully Worked Exam-Style Question
Reading syntax tables is passive. Let us apply the whole toolkit to a single problem the way you would in the exam. This is a specimen question modelled on the OCR J277 paper format, not a copied past-paper question.
A quiz program stores a player's five round scores in an array. Write a program using the OCR Exam Reference Language that:
- asks the player to enter five scores, each between 0 and 20 inclusive,
- rejects any score outside that range and asks again,
- stores the valid scores in an array,
- calculates and prints the total and the average,
- prints "Well done" if the average is 15 or more.
The examiner is testing several skills at once here: array declaration, count-controlled iteration, input validation with a condition-controlled loop, running totals, arithmetic, and selection. That combination is exactly what a 6- to 8-mark "write a program" question looks like. Plan before you write. The structure is: a for loop to run five times; inside it, a do...until (or while) loop that keeps asking until the input is valid; then, after the loop, the total, the average and the final if.
array scores[5]
total = 0
for i = 0 to 4
valid = false
do
entry = int(input("Enter score " + str(i + 1) + " (0-20): "))
if entry >= 0 AND entry <= 20 then
valid = true
else
print("Out of range. Try again.")
endif
until valid == true
scores[i] = entry
total = total + entry
next i
average = total / 5
print("Total: " + str(total))
print("Average: " + str(average))
if average >= 15 then
print("Well done")
endif
Walk through why each choice earns marks. The array is declared with the correct size, scores[5], and the loop runs for i = 0 to 4 — five iterations, correctly zero-indexed, which is the single most common place candidates lose a mark by writing 1 to 5 and going out of bounds. The validation uses a do...until loop because the prompt must appear at least once: this is the textbook case for a post-check loop, and choosing it deliberately is itself a marked decision. Notice the flag variable valid, set to false before the loop and only flipped to true when a good value arrives; this is the standard ERL pattern for "keep asking until the answer is acceptable," because ERL has no break. The input is cast with int(...) because input() returns a string, and comparing a string to a number would not behave as intended. The running total is accumulated inside the loop, and the average is computed once, after it. Casting with str(...) when concatenating numbers into print avoids a type mismatch. Finally the if uses >= and closes with endif.
That single question exercises roughly a third of everything in this guide. If you can write it fluently, from a blank page, in under ten minutes, your Paper 2 programming preparation is in good shape. If any part of it made you hesitate, that hesitation is your revision target — go back to the relevant section above and drill it.
Turning the Cheat Sheet into a Revision Routine
Knowing the syntax and recalling it under pressure are different things. Here is a routine that turns this reference into exam-ready fluency.
Write the syntax skeleton from memory. Once a week, on a blank sheet, write out an empty example of each construct: an if/elseif/else/endif, all three loops with their closing keywords, an array declaration, a function and a procedure. Do it without looking. Then check against this guide and circle whatever you got wrong or left out. The closing keywords (endif, endwhile, next i, endfunction, endprocedure, endswitch) are the most-forgotten items, so pay them special attention — writing the closing keyword immediately after the opening one, before you fill in the body, is a habit that eliminates the single most common ERL mistake.
Trace before you write. Tracing is where the reliable marks are, and it is a skill you can practise passively — on the bus, in a spare five minutes. Take any snippet with a loop and a couple of variables, draw a trace table with one column per variable and one row per iteration, and fill it in. Force yourself to update every variable on every line. The discipline of never skipping a row is exactly what earns method marks even when your final answer is wrong.
Translate both ways. For every construct, practise going from ERL to Python (or your language) and back again. The exam will hand you code in either direction, and the students who struggle are usually fluent in one direction only — they can read ERL but freeze when asked to produce it, or vice versa. A quick drill: take a ten-line Python function you wrote in class and rewrite it in strict ERL, then check that you used then, endif, elseif, MOD/DIV, and inclusive for ranges correctly.
Rehearse the string traps in isolation. The two string operations that cost the most marks are .substring(start, length) and .length. Because .substring takes a length as its second argument — unlike Python slicing, which takes an end index — the same-looking numbers give different results. Drill a handful of these until the difference is automatic: "Computer".substring(0, 4) is "Comp"; "Computer".substring(3, 2) is "pu". Getting these right in a trace question is free marks that many candidates give away.
Simulate the paper. In the final fortnight, answer whole programming questions from a blank page under a timer, then mark them against a mark scheme. This is the only way to calibrate how long an 8-mark program actually takes you and to expose the constructs you think you know but fumble when the clock is running.
Quick-Reference Keyword Map
When you are revising against the clock, the fastest thing to internalise is the one-to-one map between the language you programmed in and the reference language the exam expects. Everything in the left column below is something students routinely write out of habit; the right column is what OCR wants to see.
| If you habitually write (Python) | OCR Exam Reference Language expects |
|---|---|
elif | elseif |
True / False | true / false |
and / or / not | AND / OR / NOT |
% (modulus) | MOD |
// (integer division) | DIV |
** (power) | ^ |
for i in range(5): | for i = 0 to 4 … next i |
while cond: | while cond … endwhile |
def name(): (returns) | function name() … endfunction |
def name(): (no return) | procedure name() … endprocedure |
len(s) | s.length |
s[1:4] (start, end) | s.substring(1, 3) (start, length) |
s.upper() / s.lower() | s.upper / s.lower |
ord(c) / chr(n) | ASC(c) / CHR(n) |
no then keyword | if cond then |
| indentation closes a block | explicit endif / endwhile / next |
Print this table, or copy it onto a revision card, and read it the night before Paper 2. Nine times out of ten, when a student loses marks on an otherwise-correct program, it is because a habit from the left column leaked into an answer that should have used the right column.
Practise with LearningBro
Reading about pseudocode syntax is a good start, but the real skill comes from writing it repeatedly under exam conditions. You can practise OCR pseudocode questions, algorithm tracing, and programming challenges across LearningBro's OCR GCSE Computer Science courses. Working through questions topic by topic is the fastest way to build fluency with the Exam Reference Language so that it feels natural by the time you sit the exam.
Three courses map directly onto the skills in this cheat sheet. The Programming Fundamentals course works through variables, operators, selection, iteration, arrays, string manipulation and subroutines one lesson at a time. The Algorithms course drills the tracing and searching/sorting questions where ERL reading skills earn marks. And the Producing Robust Programs course covers input validation, defensive design and the trace-table debugging that the worked question above relies on. The AI tutor on every lesson will trace a snippet with you step by step the moment you get stuck.