This is the longest topic in the specification and the one that carries most of the Paper 1 marks. It covers the statements every program is built from, the operators that do the work, the structures that hold data, and the discipline that makes code safe to rely on. Two of the specification's supported languages are Python and C#, so the examples here use Python-style syntax with the AQA pseudo-code where the specification demands it. Learn this as something you write, not something you memorise.
What you need to know
What a subroutine is
A subroutine is a named 'out of line' block of code that may be executed (called) by simply writing its name in a program statement. The code sits outside the main flow of the program and runs only when it is called. Procedures do a job; functions do a job and hand a value back.
Key fact: A subroutine is a named block of code that runs when its name is written in a program statement.
Why use them
Explain the advantages of using subroutines in programs. You write the code once and call it many times, so a program is shorter and easier to read. A bug in the code has to be fixed once. And when the same task appears in several places — validating every input, adding up a total, drawing a box — one subroutine keeps them all identical instead of letting them drift apart.
Key fact: Subroutines avoid repeating code, make programs easier to read and mean a bug is fixed in one place.
Parameters
Describe the use of parameters to pass data within programs. A parameter is a value passed into a subroutine when it is called. Students should be able to use subroutines that require more than one parameter, and describe how data is passed to a subroutine using parameters. So a subroutine called CalculateArea(width, height) receives two values from the caller.
Key fact: A parameter is a value passed into a subroutine when it is called.
Return values
Use subroutines that return values to the calling routine, and describe how data is passed out of a subroutine using return values. A function calculates something and sends the answer back, where the caller can store it in a variable or use it in a calculation. A procedure performs an action and returns nothing.
Key fact: A function passes a value back to the caller; a procedure does not.
Local variables
Subroutines may declare their own variables, called local variables, and these usually only exist while the subroutine is executing and are only accessible within the subroutine. That is a feature, not a bug: it means a subroutine cannot be accidentally changed by something outside it, and two subroutines can each use a variable called count without interfering.
Key fact: Local variables exist only while the subroutine runs and cannot be accessed from outside it.
The structured approach
Describe the structured approach to programming, including modularised programming, clear well-documented interfaces (local variables, parameters and return values), and explain the advantages of it. In practice this means breaking a program into named modules with clear boundaries, so that each part does one job and can be understood, tested and changed on its own.
Key fact: The structured approach means modularised programs with clear, documented interfaces.
Arguments and parameters
Teachers should be aware that the terms arguments and parameters are sometimes used but in examinable material we will use the term parameter to refer to both of these. So in an exam answer, say parameter. If you use 'argument' in a mark scheme question it may not match, and it is the same concept in any case.
Key fact: In exam answers use the word parameter for both what is passed in and the name it is received under.
Flashcards
What is a subroutine?
A named out of line block of code that is executed by writing its name in a program statement.
What is a parameter?
A value passed into a subroutine when it is called.
What is a return value?
A value a function passes back to the calling routine.
What is a local variable?
A variable declared inside a subroutine that usually only exists while the subroutine is executing and is only accessible within it.
Name two advantages of using subroutines.
You avoid repeating code and you only have to fix a bug in one place; a program is also shorter and easier to read.
What does the structured approach involve?
Modularised programming with clear, well-documented interfaces built from local variables, parameters and return values.
Which word should you use in an exam answer for a value passed to a subroutine?
Parameter.
Exam questions
Written in the style of AQA Computer Science, with a mark scheme for each one. No question here is a real past paper question.
mcq1 mark
Which statement about local variables is correct?
They can be accessed from anywhere in the program
They only exist while the subroutine that declares them is executing
They are stored permanently on the hard disk
They must be passed in as parameters
Mark scheme: 1 mark for identifying that local variables usually only exist while the subroutine is executing and are only accessible within that subroutine.
short3 marks
Explain in English the difference between a parameter and a return value, and give one example of each.
Mark scheme: 1 mark for stating that a parameter is a value passed into a subroutine when it is called. 1 mark for stating that a return value is a value a subroutine passes back to the caller. 1 mark for giving a correct example of each, such as width and height passed into a CalculateArea subroutine and the area returned back.
six6 marks
Explain in English the structured approach to programming and what advantages it gives a program.
Mark scheme: Level 1 (1-2 marks): A short answer saying a program is broken into named modules with clear interfaces. Level 2 (3-4 marks): A structured answer covering subroutines, parameters, return values and local variables. Level 3 (5-6 marks): A detailed answer explaining what a subroutine is and how it is called, explaining how data goes in through parameters and comes back through return values, explaining that local variables exist only while the subroutine runs and that this protects them from outside interference, describing the structured approach as modularised programming with clear well-documented interfaces, and explaining the advantages: no repeated code, a bug fixed in one place, and modules that can be understood, tested and changed independently.