What are the core programming constructs, and how do subroutines, scope, parameters and recursion structure a program?
Programming techniques: sequence, selection and iteration, recursion, the use of subroutines (procedures and functions) with parameters passed by value and by reference, local and global variable scope, and the features of an integrated development environment (IDE).
An OCR H446 answer on programming techniques: sequence, selection and iteration, recursion, subroutines (procedures and functions) with parameters passed by value or by reference, local and global variable scope, and the features of an integrated development environment.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
What this dot point is asking
OCR wants the core programming constructs (sequence, selection, iteration), recursion, subroutines with parameters passed by value or by reference, local and global variable scope, and the features of an IDE. Expect questions to write a short subroutine (often recursive) and to explain parameters and scope.
The answer
Sequence, selection and iteration
for i = 1 to 5 // count-controlled iteration
if i MOD 2 == 0 then // selection
print(i, "is even")
else
print(i, "is odd")
endif
next i
Recursion
Subroutines, parameters and scope
Examples in context
Tree and graph traversals are naturally recursive, while a simple total is better as a loop. Passing a large array by reference avoids copying it; passing a single value by value protects the caller. Local variables keep subroutines self-contained and testable. IDEs such as Visual Studio or PyCharm provide an editor, error highlighting, auto-complete, a debugger with breakpoints and watch windows, and run tools that catch mistakes early. OCR links this to object-oriented techniques, to the algorithms in Component 02 (many expressed recursively), and to the development stage of the Programming Project.
Try this
Q1. State the difference between a count-controlled and a condition-controlled loop. [2 marks]
- Cue. A count-controlled loop (for) runs a fixed number of times; a condition-controlled loop (while/repeat until) runs until a condition is met, used when the count is not known in advance.
Q2. State what every recursive subroutine must have to avoid infinite recursion. [1 mark]
- Cue. A base case (a stopping condition solved directly), with the recursive case moving towards it.
Q3. Explain one advantage of passing a parameter by reference. [2 marks]
- Cue. It avoids copying large data and lets the subroutine modify the caller's original variable directly.
Exam-style practice questions
Practice questions written in the style of OCR exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
OCR 20196 marksExplain the difference between passing a parameter by value and by reference, and explain the difference between a local and a global variable.Show worked answer →
By value versus by reference (up to 3): passing by value sends a copy of the data to the subroutine, so changes inside the subroutine do not affect the original variable. Passing by reference sends the memory address (a reference) of the variable, so the subroutine works on the original and any changes are reflected in the caller. By value is safer (no side effects); by reference avoids copying large data and lets a subroutine modify the caller's variable.
Local versus global (up to 3): a local variable is declared inside a subroutine and exists only while that subroutine runs, accessible only within it, which avoids unintended interference. A global variable is declared outside all subroutines and is accessible throughout the whole program for its lifetime, which is convenient but risks accidental modification and makes code harder to maintain. Markers reward copy-versus-address for parameters and the scope/lifetime distinction for variables.
OCR 20216 marksA subroutine to calculate a factorial can be written iteratively or recursively. Write the recursive version in pseudocode, and explain one advantage and one disadvantage of recursion compared with iteration.Show worked answer →
Recursive factorial (up to 3):
function factorial(n)
if n <= 1 then
return 1
else
return n * factorial(n - 1)
endif
endfunction
Award marks for a correct base case ( returns 1), the recursive call on , and multiplying by .
Advantage and disadvantage (up to 3): advantage, recursion can express naturally recursive problems (factorials, tree traversal, divide and conquer) more concisely and clearly than iteration. Disadvantage, each call adds a stack frame, so deep recursion uses more memory and can cause a stack overflow, and it is generally slower than the equivalent loop. Markers reward a correct base case and recursive step plus one valid advantage and disadvantage.
Related dot points
- Thinking abstractly: the nature and need for abstraction, representational and procedural abstraction, and the use of models; thinking ahead and decomposition: breaking a problem into smaller sub-problems.
An OCR H446 answer on the computational thinking skills of abstraction and decomposition: the nature and need for abstraction, representational and procedural abstraction and the use of models, and decomposing a problem into smaller, more manageable sub-problems.
- Thinking ahead: identifying inputs and outputs, preconditions, caching and reusable program components; thinking procedurally: identifying the steps and the order of a solution and the components that can be reused.
An OCR H446 answer on the computational thinking skills of thinking ahead and thinking procedurally: identifying inputs, outputs, preconditions, caching and reusable components, and determining the steps and the order of a procedural solution.
- Object-oriented programming techniques in practice: defining classes with attributes and methods, constructors and instantiation, getters and setters for encapsulation, inheritance and method overriding for polymorphism, and the benefits of an object-oriented design.
An OCR H446 answer on object-oriented programming techniques in practice: defining classes with attributes and methods, constructors and instantiation, getters and setters for encapsulation, inheritance with method overriding for polymorphism, and the benefits of object-oriented design.
- Programming paradigms (procedural, low-level / assembly and object-oriented), the need for and characteristics of different levels of programming language, and the core principles of object-oriented programming: classes, objects, methods, attributes, encapsulation, inheritance and polymorphism.
An OCR H446 answer on programming paradigms and language levels: procedural, low-level and object-oriented programming, the characteristics of high-level versus low-level languages, and the OOP principles of classes, objects, methods, attributes, encapsulation, inheritance and polymorphism.
- Big-O notation for time and space complexity: the constant, logarithmic, linear, linearithmic, polynomial and exponential complexity classes, how to determine the Big-O of an algorithm, and using it to compare and judge the suitability of algorithms.
An OCR H446 answer on Big-O notation: the constant, logarithmic, linear, linearithmic, polynomial and exponential complexity classes for time and space, how to determine an algorithm's Big-O, and using it to compare algorithms and judge their suitability.