Uni-Sine
UK examsGCSE

OCR GCSE Computer Science Exam Reference Language (J277): every command with examples

Paper resets in

Formula sheet

The card below opens today's Computer Science paper with the language reference in the drawer, so you practise reading and writing code the way the paper presents it. The tables follow, in our own layout. The commands are those in OCR's specification section 3c, so check it before you rely on anything here. The specification does not say whether the language is printed as a sheet in the paper, so learn it as if it is not.

Formula sheet

GCSE Computer Science

Open formula sheet

Operators

MOD gives the remainder after division and DIV gives the whole number quotient.

ConceptKeywords and symbolsExample
Comparison== != < <= > >=x >= 18
Arithmetic+ - * / ^ MOD DIV17 MOD 5 gives 2, 17 DIV 5 gives 3
BooleanAND OR NOTage >= 13 AND age < 20

Variables, input and output

ConceptKeywords and symbolsExample
Comment//// this is a comment
Assignment=x = 3
Constantconstconst vat = 0.2
Global variableglobalglobal userID = "Cust001"
Inputinput(...)myName = input("Enter a name")
Outputprint(...)print("Hello")
Castingstr() int() float() real() bool()int("3") gives 3

Iteration and selection

ConceptKeywords and symbolsExample
Count-controlled loopfor ... to ... nextfor i = 0 to 9 ... next i
Loop with a stepstepfor i = 10 to 0 step -1
Condition-controlled loop, test firstwhile ... endwhilewhile answer != "Correct"
Condition-controlled loop, test lastdo ... untildo ... until answer == "Correct"
Selectionif ... then elseif ... then else endifif mark >= 50 then
Case selectionswitch ... : case ... : default: endswitchswitch day : case "Sat":

Strings

In .substring(x, i), x is the starting index and i is the number of characters. Strings are indexed from 0.

ConceptKeywords and symbolsExample
Length.lengthsubject.length
Substring.substring(x, i)subject.substring(3, 5)
Left and right.left(i) .right(i)subject.left(4)
Concatenation+print("Hello " + name)
Upper and lower case.upper .lowersubject.upper
ASCII conversionASC(...) CHR(...)ASC('A') gives 65

Files and arrays

Arrays are indexed from 0, so array colours[5] has indexes 0 to 4, and an array stores one data type.

ConceptKeywords and symbolsExample
Open and close a fileopen(...) .close()myFile = open("sample.txt")
Read a line.readLine()myFile.readLine()
Write a line.writeLine(...)myFile.writeLine("New line")
End of file.endOfFile()while NOT myFile.endOfFile()
Create a filenewFile(...)newFile("myText.txt")
One dimensional arrayarray name[n]array colours[5]
Two dimensional arrayarray name[r, c]array gameboard[8, 8]
Assign an elementname[i] = ...names[3] = "Noni"

Subprograms and random numbers

random(1, 6) gives a random integer from 1 to 6 inclusive, and random(-1.0, 10.0) gives a real number in that range.

ConceptKeywords and symbolsExample
Procedureprocedure ... endprocedureprocedure greet(name)
Functionfunction ... return ... endfunctionfunction double(n)
Call a procedurename(parameters)greet("Ada")
Call a functionname(parameters)y = double(4)
Random numberrandom(..., ...)x = random(1, 6)

Reading and writing ERL

Read the code from the top, one line at a time, and keep a table of the variables. Take this short program, which averages five marks:

total = 0
for i = 0 to 4
    mark = int(input("Enter mark"))
    total = total + mark
next i
average = total / 5
print("Average: " + str(average))

The loop runs for i = 0, 1, 2, 3 and 4, which is 5 times. Suppose the marks entered are 12, 15, 9, 18 and 6. Trace the variables line by line:

imarktotal
01212
11527
2936
31854
4660

The program then prints the word Average followed by 12, because 60 / 5 = 12. The input function returns text, so the int() casting is needed before adding.

A function that returns a value

function isEven(n)
    if n MOD 2 == 0 then
        return true
    else
        return false
    endif
endfunction

print(isEven(17))

17 MOD 2 is 1, so the condition is false and the program prints false. A function returns a value, so store it in a variable or print it. A procedure does not return one.

What the reference does not give you

  • How to choose the structure. It lists a for loop, a while loop and a do until loop. Which one a question needs is your decision.
  • Algorithms. Searching, sorting and the other algorithms in the specification are not written out. You need to know how they work.
  • Logic and design tools. Flowchart symbols, trace tables and the rest of the Component 2 skills sit outside the language reference.
  • Every function of every language. If you answer in a high-level language, the reference does not cover its own syntax.
  • Errors. It does not tell you what a syntax or logic error looks like, so learn to spot both.

How to use ERL in the exam

  1. Read the whole program once before you trace it.
  2. Make a table with a column for each variable, and fill in one row for each pass of a loop.
  3. Remember that arrays and strings are indexed from 0.
  4. In a "write" question use the exact keywords: endif, endwhile, next, endfunction.
  5. Check boundary values: a for loop to 9 includes 9, and DIV and MOD behave differently from /.

ERL and other boards' languages

OCR's specification says answers in pseudocode, natural English or bullet points will not be awarded marks where a response must be in ERL or a high-level language. Other boards use their own language references,. If you sit AQA or Edexcel, use the language your board names.

The specification says Component 2 lasts 1 hour 30 minutes. For the boards, papers and grade boundaries, see our GCSE Computer Science guide.

Use the sheet with today's paper

Uni-Sine publishes a free daily paper for GCSE Computer Science. It is a short timed paper of 8 questions worth 25 to 35 marks, not a full OCR paper, and it is not written by OCR. Open the reference, set a timer and write the code you use at the top of each answer. After marking, look at any question where you used the wrong keyword or the wrong loop.

Common mistakes

  • Off by one in a for loop. for i = 0 to 9 runs 10 times, from 0 to 9 inclusive.
  • Mixing up MOD and DIV. MOD is the remainder and DIV is the whole number quotient.
  • Forgetting to cast input. input() gives text, so use int() or float() before arithmetic.
  • Counting arrays from 1. array colours[5] has indexes 0 to 4.
  • Missing the end keyword. Every if has an endif, and every while has an endwhile.
  • Using = to compare. Assignment is =, and comparison is ==.

Exam answers

The answers and a worked mark scheme come with today's paper once it is marked. Sit the paper with the sheet open beside you, mark it, and the worked answers show which line of the sheet each question wanted. We do not publish official or past paper answers.

Common questions

What is the OCR Exam Reference Language?
It is the programming language OCR uses for all programming code given in its GCSE Computer Science (J277) examination papers.
Do I have to write my answers in ERL?
In Component 2 Section B, questions that ask you to write or refine algorithms must be answered in either ERL or the high-level programming language you are familiar with.
Will I lose marks for a small syntax error in ERL?
OCR says it will avoid penalising minor syntax errors where a response uses ERL or a high-level language, though it will assess precision.
Are pseudocode answers accepted?
Not where a response must be in ERL or a high-level language: OCR says answers in pseudocode, natural English or bullet points will not be awarded marks there.
What is the difference between MOD and DIV in ERL?
MOD gives the remainder and DIV gives the whole number quotient. 17 MOD 5 is 2 and 17 DIV 5 is 3.

Revision cards

Say the answer first, then flip the card to check it.

Where to go next

  • Solve it

    Code Editor

    Write and run code right in your browser

    Open the tool
  • Learn it

    Programming Languages

    Compiled vs interpreted, paradigms and the evolution of how we talk to machines

    Start the course
  • Test it

    GCSE Computer Science

    A new exam-style paper every day, with instant marking and a mark scheme

    Start today's paper
Read next
UK · GCSEOCR GCSE Computer Science (J277): papers and gradesOCR GCSE Computer Science (J277) explained: two 1 hour 30 minute papers, no calculator, what is on each, worked examples and June 2026 boundaries.