Exam Reference Language (ERL) Quick Reference
This is a complete list of valid ERL syntax as specified by OCR for the J277 specification.
1. Variables and Constants
| Syntax | Description |
variableName = value | Assigns a value to a variable based on the given data type. |
const name = value | Creates a constant which cannot be changed later. |
global variableName | Declares a variable that is accessible across all subroutines. |
str(x), int(x), float(x), bool(x) | Type casting (converting between data types). |
2. Input & Output
| Syntax | Description |
print("Hello") | Outputs data to the screen. |
name = input("Prompt") | Receives input from the keyboard. |
3. Operators
| Syntax | Description |
+, -, *, /, ^ | Standard arithmetic: Add, Subtract, Multiply, Divide, Exponentiation. |
MOD | Modulo arithmetic. Finds the remainder (e.g., 10 MOD 3 is 1). |
DIV | Integer division. Finds the whole number of divisions (e.g., 10 DIV 3 is 3). |
==, !=, <, <=, >, >= | Comparison operators (Equal, Not equal, Less than, etc.). |
AND, OR, NOT | Logical (Boolean) operators. |
4. Selection (IF & SWITCH)
| Syntax | Example |
if ... then
elseif ... then
else
endif
|
if age >= 18 then
print("Adult")
elseif age >= 13 then
print("Teen")
else
print("Child")
endif
|
switch ... :
case ...:
default:
endswitch
|
switch choice:
case "A":
print("Apple")
case "B":
print("Banana")
default:
print("Invalid")
endswitch
|
5. Iteration (Loops)
| Type | Example |
| Count-controlled (FOR) |
for x = 0 to 9
print(x)
next x
|
| Condition-controlled (WHILE) |
while password != "123"
password = input("Try again")
endwhile
|
| Condition-controlled (DO UNTIL) |
do
password = input("Try again")
until password == "123"
|
6. Arrays
| Syntax | Description |
array names[5] | Creates a 1D array of length 5 (indices 0 to 4). |
array grid[3, 3] | Creates a 2D array (3 rows, 3 columns). |
names[0] = "Bob" | Assigns a value to a 0-indexed element. |
7. Subroutines
| Syntax | Example |
| Procedure (No return value) |
procedure sayHello(name)
print("Hello " + name)
endprocedure
|
| Function (Returns a value) |
function addMe(x, y)
return x + y
endfunction
|
8. File Handling
| Syntax | Description |
myFile = openRead("data.txt") | Opens a file for reading. |
myFile = openWrite("data.txt") | Opens a file for writing. |
myFile.readLine() | Reads a single line from the file. |
myFile.writeLine(data) | Writes a single line to the file. |
myFile.endOfFile() | Returns True if the end of the file has been reached. |
myFile.close() | Closes the file. |
9. String Operations
| Syntax | Description |
stringname.length | Returns the number of characters in the string. |
stringname.substring(start, length) | Returns a portion of the string. Example: "Hello".substring(0,2) is "He". |
stringname.upper | Converts the string to UPPERCASE. |
stringname.lower | Converts the string to lowercase. |