OCR J277 · Component 02 · §2.2 · Paper 2

§2.2 Programming Fundamentals

What are the essential building blocks of a program — and how are data stored, manipulated, and structured?

Every program, regardless of language, is built from the same three constructs: sequence (instructions run in order), selection (if-else branches choose between paths), and iteration (loops repeat a block). Data is stored in variables (changeable) or constants (fixed), typed appropriately — integer, real, boolean, character, string — and manipulated using arithmetic, comparison, and boolean operators.

OCR's additional programming techniques extend into data structures and abstraction. Arrays (1D and 2D) group related data under one name. Records group related fields of different types into one entity. File handling (open, read, write, close) allows data to persist beyond a single program run. SQL provides a way to query structured data: SELECT FROM WHERE is the basic pattern. Functions return values; procedures do not — both reduce repetition and improve maintainability. Students at St Leonards write answers in Python; the OCR Exam Reference Language (ERL) is also accepted in the exam.

Write a Python function that takes a list of integers and returns the average. Separately, write a procedure that writes a student's name and score to a text file. What data type would you use for: a student's age; their grade (A–F); their average score (e.g. 73.4); whether they have submitted their work?

Core constructs (OCR ERL)

IF condition THEN ... ELSEIF ... ELSE ... ENDIF
FOR i = 1 TO 10 ... NEXT i (count-controlled)
WHILE condition DO ... ENDWHILE (pre-condition)
FUNCTION name(params) RETURN value ENDFUNCTION
PROCEDURE name(params) ... ENDPROCEDURE
SELECT name FROM table WHERE condition (SQL)

What students must understand

Linking questions

Practice

Video Support

Craig'n'Dave — OCR J277
2.2 Programming fundamentals — unit playlist