You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
This lesson covers pseudocode and the OCR Exam Reference Language conventions, as required by OCR J277 Section 2.1. Pseudocode is used extensively in the OCR GCSE Computer Science exam, so understanding the OCR reference language is essential.
Pseudocode is a way of writing algorithms that looks like a simplified programming language but is not tied to any specific language. It uses structured, English-like statements to describe the logic of an algorithm.
Pseudocode is:
OCR Exam Tip: In the exam, pseudocode questions use the OCR Exam Reference Language. You do not need to use perfect syntax, but you should follow the OCR conventions. The reference language guide is available on the OCR website and will be familiar from your practice.
Variables are assigned using =:
name = "Alice"
age = 16
total = 0
| Data Type | Description | Example |
|---|---|---|
| Integer | Whole number | age = 16 |
| Real | Decimal number | price = 9.99 |
| Boolean | True or False | found = true |
| Character | Single character | grade = 'A' |
| String | Text (sequence of characters) | name = "Alice" |
| Operator | Meaning | Example | Result |
|---|---|---|---|
+ | Addition | 3 + 2 | 5 |
- | Subtraction | 10 - 4 | 6 |
* | Multiplication | 5 * 3 | 15 |
/ | Division | 10 / 3 | 3.33... |
MOD | Modulus (remainder) | 10 MOD 3 | 1 |
DIV | Integer division (quotient) | 10 DIV 3 | 3 |
^ | Exponentiation (power) | 2 ^ 3 | 8 |
OCR Exam Tip: MOD and DIV are commonly tested. MOD gives the remainder (10 MOD 3 = 1), DIV gives the whole number result of division (10 DIV 3 = 3). Learn these well — they appear in many exam questions.
// Input
name = input("Enter your name: ")
// Output
print("Hello")
print(name)
print("Your score is " + score)
if score >= 50 then
print("Pass")
endif
if score >= 50 then
print("Pass")
else
print("Fail")
endif
if score >= 70 then
print("Distinction")
elseif score >= 50 then
print("Pass")
else
print("Fail")
endif
switch day:
case "Monday":
print("Start of the week")
case "Friday":
print("End of the week")
default:
print("Midweek")
endswitch
for i = 1 to 10
print(i)
next i
for i = 0 to 20 step 2
print(i)
next i
while answer != "quit"
answer = input("Enter command: ")
endwhile
do
password = input("Enter password: ")
until password == "secret"
| Loop Type | When to Use | Checks Condition |
|---|---|---|
| FOR | When you know how many times to repeat | Before each iteration |
| WHILE | When you do not know how many times — check before executing | Before each iteration (may not execute at all) |
| DO...UNTIL | When you want to execute at least once | After each iteration (always executes at least once) |
OCR Exam Tip: Know when to use each loop type. Use FOR when the number of repetitions is known. Use WHILE when the condition must be checked BEFORE each iteration. Use DO...UNTIL when the loop body must execute AT LEAST ONCE. This distinction is commonly tested.
| Operator | Meaning | Example |
|---|---|---|
== | Equal to | if x == 5 |
!= | Not equal to | if x != 0 |
< | Less than | if age < 18 |
<= | Less than or equal to | if score <= 100 |
> | Greater than | if temp > 30 |
>= | Greater than or equal to | if marks >= 50 |
| Operator | Meaning | Example |
|---|---|---|
AND | Both conditions must be true | if age >= 13 AND age <= 19 |
OR | At least one condition must be true | if day == "Saturday" OR day == "Sunday" |
NOT | Reverses the condition | if NOT found |
| Operation | Syntax | Example | Result |
|---|---|---|---|
| Length | string.length | "Hello".length | 5 |
| Substring | string.substring(start, length) | "Hello".substring(1, 3) | "ell" |
| Uppercase | string.upper | "hello".upper | "HELLO" |
| Lowercase | string.lower | "HELLO".lower | "hello" |
| ASCII | ASC(char) | ASC('A') | 65 |
| Character | CHR(code) | CHR(65) | 'A' |
// Declare an array
array names[5]
// Assign values
names[0] = "Alice"
names[1] = "Bob"
names[2] = "Charlie"
// Access values
print(names[0]) // Outputs: Alice
// Loop through an array
for i = 0 to 4
print(names[i])
next i
Note: In OCR pseudocode, arrays are zero-indexed (the first element is at index 0).
procedure greet(name)
print("Hello " + name)
endprocedure
// Calling a procedure
greet("Alice")
function calculateArea(length, width)
area = length * width
return area
endfunction
// Calling a function
result = calculateArea(5, 3)
print(result) // Outputs: 15
OCR Exam Tip: Know the difference: a procedure performs an action but does not return a value. A function performs a calculation and returns a value that can be stored in a variable. The exam may ask you to write either one.
Pseudocode is a structured, language-independent way of writing algorithms. The OCR Exam Reference Language uses specific conventions for variables, input/output, selection, iteration, arrays, and subprograms. For the OCR J277 exam, you must be able to read, write, and trace through pseudocode. Pay particular attention to MOD/DIV, loop types, and the difference between functions and procedures.
A school wants to give each student a 4-digit PIN to log into a library kiosk. The kiosk must accept an attempted PIN, compare it with the stored PIN, and either grant access or lock the account after three wrong attempts.
Design in OCR pseudocode:
storedPIN = "4721"
attempts = 0
locked = false
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.