All exams← All GCSE Computer Science (OCR) notes

Programming fundamentals: GCSE Computer Science (OCR) revision notes

Revision notes

What are programming fundamentals?

This is the core toolkit every programmer needs: variables, constants, sequence, selection, iteration, operators and data types. OCR J277 expects you to read, trace and write pseudocode or code (Python-style) using these building blocks.

Data types

  • Integer: whole numbers, e.g. 7 or -3.
  • Real (float): numbers with a decimal point, e.g. 3.14.
  • Boolean: only True or False.
  • Character: a single letter, digit or symbol.
  • String: a sequence of characters, e.g. 'hello'.
  • Casting converts one type to another, e.g. int('5') turns the string '5' into the integer 5. Common mistake: forgetting that input() in Python always returns a string, so numbers typed in must be cast before doing maths on them.

Variables and constants

A variable stores a value that can change while the program runs; a constant stores a value that stays fixed. Use meaningful identifier names. Assignment uses = (e.g. score = 0), while == tests equality in a condition. Mixing these up is one of the most common exam and coding errors.

The three constructs

  • Sequence: instructions run in order, top to bottom.
  • Selection: IF, ELSE IF (ELIF), ELSE branch the logic based on a condition; nested IFs place one selection inside another.
  • Iteration: count-controlled loops (FOR) repeat a set number of times; condition-controlled loops (WHILE, or REPEAT...UNTIL) repeat until a condition is met. A WHILE loop checks the condition BEFORE running the body, so it might run zero times; REPEAT...UNTIL checks AFTER, so it always runs at least once.

Operators

  • Arithmetic: + - * / (division), // (integer/floor division, drops remainder), MOD or % (remainder), ^ or ** (exponent/power).
  • Relational (comparison): > < >= <= == != — these always produce a Boolean result.
  • Boolean/logical: AND, OR, NOT combine or invert conditions, e.g. IF age >= 18 AND hasID == True.

String handling and arrays

Know string operations: length (LEN), concatenation (+), substring/slicing, converting case, and finding a character's position. Arrays (or lists) store multiple values under one identifier, indexed from 0 in most exam pseudocode and in Python — a classic off-by-one mistake is thinking the first item is index 1.

Nested and combined structures

Expect exam questions that nest loops inside selections, or selections inside loops, then ask you to trace the output by hand — write out variable values step by step in a trace table rather than guessing.

Key facts

Flashcards

What is the difference between = and == in code?
= is assignment (stores a value in a variable); == is a comparison operator that tests if two values are equal.
tap to reveal
Why must you cast the result of input() before doing maths with it?
input() always returns a string, so it must be cast with int() or float() before it can be used in arithmetic.
tap to reveal
What index does the first element of an array have?
0 — arrays and lists are zero-indexed.
tap to reveal
What does the // operator do?
Integer (floor) division — divides and discards the remainder, e.g. 7 // 2 = 3.
tap to reveal
What does MOD (or %) return?
The remainder after division, e.g. 7 MOD 2 = 1.
tap to reveal
When does a WHILE loop check its condition?
Before running the loop body, so the body may run zero times.
tap to reveal
When does a REPEAT...UNTIL loop check its condition?
After running the loop body, so the body always runs at least once.
tap to reveal
What type of loop is a FOR loop?
Count-controlled — it repeats a known, fixed number of times.
tap to reveal
Name the four core data types tested in OCR Programming Fundamentals.
Integer, real (float), Boolean, and character/string.
tap to reveal
What do the Boolean operators AND, OR and NOT do?
They combine or invert conditions and always produce a True or False result.
tap to reveal
What is casting?
Converting a value from one data type to another, e.g. int('5') to 5, or str(5) to '5'.
tap to reveal
What is the difference between a variable and a constant?
A variable's stored value can change while the program runs; a constant's value stays fixed.
tap to reveal
What are the three basic programming constructs?
Sequence (instructions in order), selection (IF/ELIF/ELSE branching), and iteration (loops).
tap to reveal
What does nested selection mean?
Placing one IF statement entirely inside the body of another IF statement.
tap to reveal
Why is a trace table useful for loop and selection questions?
It records each variable's value step by step as the code runs, avoiding guesswork when working out the output.
tap to reveal
Practice questions

Programming fundamentals: 5 practice questions

Q1. In OCR's exam pseudocode, which statement correctly declares an integer variable called score and assigns it the value 0?
  • A.  score = 0
  • B.  DIM score AS INTEGER: 0
  • C.  INTEGER score = 0
  • D.  score = 0 AS INTEGER
Show answer & explanation
✓ Answer: A. score = 0
OCR exam reference language uses simple assignment with '=' and infers the data type from the value assigned, so 'score = 0' both declares and initialises the variable as an integer. The other forms mix in syntax from other languages (Java-style typing, VB-style DIM) that OCR's pseudocode does not use.
Q2. A programmer writes a loop that must repeat exactly 10 times, counting from 1 to 10. Which construct is most appropriate?
  • A.  A condition-controlled WHILE loop
  • B.  A count-controlled (FOR) loop
  • C.  A nested IF statement
  • D.  A condition-controlled DO UNTIL loop
Show answer & explanation
✓ Answer: B. A count-controlled (FOR) loop
A FOR loop is a count-controlled loop, ideal when the exact number of repetitions is known in advance, such as counting 1 to 10. WHILE and DO UNTIL are condition-controlled and better suited when the number of iterations depends on a condition being met, and an IF statement does not repeat at all.
Q3. Which of the following best describes the difference between a variable and a constant?
  • A.  A variable can only be used once; a constant can be reused
  • B.  A variable's value can change while a program runs; a constant's value is fixed once set
  • C.  A constant must be declared inside a function; a variable cannot be
  • D.  A variable stores text; a constant stores numbers
Show answer & explanation
✓ Answer: B. A variable's value can change while a program runs; a constant's value is fixed once set
A variable is a named storage location whose value can be updated during program execution, whereas a constant is given a value that stays the same throughout the run, such as PI = 3.14. Data type has nothing to do with the variable/constant distinction, which is a common misconception.
Q4. What will the expression 17 MOD 5 evaluate to?
  • A.  12
  • B.  3.4
  • C.  2
  • D.  3
Show answer & explanation
✓ Answer: C. 2
MOD returns the remainder after integer division, and 17 divided by 5 gives 3 remainder 2, so 17 MOD 5 = 2. Confusing MOD with DIV (integer division, which gives 3) is a common error.
Q5. What will the expression 17 DIV 5 evaluate to?
  • A.  2
  • B.  3.4
  • C.  3
  • D.  0
Show answer & explanation
✓ Answer: C. 3
DIV performs integer division and discards any remainder, so 17 DIV 5 gives 3 (since 5 goes into 17 three whole times). 3.4 is the result of ordinary division, not integer division, which is why that option is a common mistake.
Test yourself
See the GCSE Computer Science (OCR) page

More GCSE Computer Science (OCR) topics