Skip to main content
EnglandComputer ScienceSyllabus dot point

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.

Generated by Claude Opus 4.814 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this dot point is asking
  2. The answer
  3. Examples in context
  4. Try this

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 (n1n \le 1 returns 1), the recursive call on n1n-1, and multiplying by nn.

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

Sources & how we know this