Skip to topic
    ← Back to course topics

    Structured programming and subroutines (procedures and functions) — AQA GCSE Computer Science

    Structured programming decomposes complex problems into smaller, manageable subroutines such as functions and procedures to improve readability and code reuse. Master the core difference: functions always return a value to the calling routine, whereas procedures execute a sequence of statements without returning a value.

    Structured programming and subroutines (procedures and functions) explained

    A subroutine can declare several parameters, separated by commas, and a call must then supply the same number of arguments in the same order.

    Read the full explanation

    For example, a procedure to record a score might take a player name and a points value; the call passes a string and an integer in that order, and inside the subroutine each parameter holds its matching argument. Order matters: swapping arguments sends the wrong data to each parameter. Multi-parameter subroutines let one routine handle related data together, such as calculating an area from length and width, and returning or displaying a result. Learners should write definitions and matching calls, and trace which value each parameter receives.

    Your focus

    1. Write a subroutine definition that declares more than one parameter.
    2. Write a call that supplies matching arguments in the correct order.
    3. Trace which value each parameter receives and the resulting output or return value.

    Which command word is this?

    Give the main characteristics of a programming technique, such as describing how parameter passing works without needing long justifications.

    Structured programming and subroutines (procedures and functions) exam tips

    Topic Overview

    Structured programming is a software development approach that breaks a large, complex problem down into smaller, self-contained sub-units known as subroutines. In AQA GCSE Computer Science, this involves mastering top-down modular design, parameter passing, and distinguishing between procedures and functions.

    Using subroutines improves code maintainability, reduces redundancy through reuse, and allows teams of developers to collaborate effectively on distinct program components. Understanding local and global variable scope ensures robust software that avoids unintended side effects during execution.

    Key Concepts
    • →Modular decomposition: Breaking down a complex program into smaller, independently testable subroutines.
    • →Procedures vs. Functions: Functions compute and return a value to the calling environment, whereas procedures execute instructions without returning a value.
    • →Parameters and Arguments: Parameters are the variable placeholders defined in the subroutine header; arguments are the actual values passed during a subroutine call.
    • →Scope of Variables: Local variables exist only within the subroutine where they are declared, while global variables remain in memory throughout the entire execution.
    Marking Points
    • A subroutine definition can list more than one parameter, separated by commas, each with a name.
    • A call must supply the same number of arguments as there are parameters.
    • Arguments are matched to parameters by position, so order matters.
    • Inside the subroutine each parameter holds its corresponding argument and can be used in expressions or output.
    • A multi-parameter subroutine can combine related data, for example computing an area from length and width.
    • Swapping the order of arguments passes the wrong data to each parameter and produces incorrect results.
    • Tracing a call shows which value each parameter receives and what the subroutine outputs or returns.
    Examiner Tips
    • 💡Write the definition and a matching call so the parameter-to-argument mapping is visible.
    • 💡State explicitly that arguments are matched by position and order matters.
    • 💡Trace one call step by step, showing the value held by each parameter.
    • 💡When asked to write an algorithm that calculates and provides a result, always declare it as a function and include an explicit 'return' statement.
    • 💡Use distinct, descriptive names for parameters to show good programming practice; avoid using identical names for global variables and subroutine parameters.
    Common Mistakes
    • Supplying fewer or more arguments than parameters: correction is to match the count exactly.
    • Reversing argument order so values land in the wrong parameters: correction is to keep the order defined in the parameter list.
    • Treating parameters as shared global values: correction is to recognise each parameter is local to that subroutine call.
    • Believing 'print' and 'return' are identical: Outputting text to the screen using a print command does not pass a value back to the program logic; only a return statement provides data to the caller.
    • Assuming global variables are always preferable: Students think global variables make coding easier, but examiners penalise failing to recognise that global variables consume memory permanently and increase the risk of accidental overwriting across subroutines.
    Revision Plan
    1. 1Step 1: Practice identifying the difference between procedures and functions in Python or AQA pseudo-code.
    2. 2Step 2: Write short subroutines that accept one or two parameters and return calculated outputs.
    3. 3Step 3: Trace programs containing both local and global variables using trace tables to observe how variable scope functions.
    4. 4Step 4: Complete past AQA Paper 1 algorithmic questions requiring subroutines and modular design.
    Exam Question Types
    • 📋Definition and comparison questions: Explaining the technical difference between a function and a procedure, or local and global variables (typically 2-4 marks).
    • 📋Code analysis and trace tables: Following subroutine calls, tracking arguments passed through parameters, and determining output values.
    • 📋Algorithm design tasks: Writing pseudocode or high-level code for a specific subroutine to solve a stated computational problem (typically 4-6 marks).
    Command Word Expectations (AQA)
    Describe

    Give the main characteristics of a programming technique, such as describing how parameter passing works without needing long justifications.

    Explain

    Set out the causes, reasons, or mechanisms clearly. For example, explain why using local variables is better practice than global variables by giving a point and its consequence.

    Write

    Construct valid pseudocode or high-level program code that satisfies all functional criteria stated in the scenario, using appropriate identifiers and constructs.

    How Students Lose Marks (Examiner Pitfalls)
    Pitfall: Confusing the distinct behaviours and return mechanisms of procedures versus functions.
    ❌ Weak Answer (Loses Marks):A function does something in code, but a procedure is used when you want to print something out.
    Example improved answer:A function performs a task and returns a value back to the calling statement, whereas a procedure performs a task and does not return a value.
    Examiner Tip: Always state explicitly that a function 'returns a value' while a procedure 'does not return a value' to secure both comparison marks.
    Pitfall: Failing to explain variable scope correctly using the terms local and global scope.
    ❌ Weak Answer (Loses Marks):Local variables are inside and global variables are outside everywhere.
    Example improved answer:A local variable is declared within a subroutine and can only be accessed within that subroutine's scope. A global variable is declared outside any subroutine and can be accessed throughout the entire program.
    Examiner Tip: Explain scope in terms of where the identifier is declared and where it is accessible in memory during runtime.
    Step-by-Step Worked Solutions

    Question: A program calculates the delivery charge for a package. If the weight is under 5 kg, the charge is £3.50. If the weight is 5 kg or more, the charge is £7.00. Write a subroutine using pseudocode or Python called 'calcDelivery' that takes 'weight' as a parameter and returns the correct delivery fee.

    1. 1.Step 1: Choose the correct subroutine type. The question specifies that the routine must return a value, so it must be declared as a function.
    2. 2.Step 2: Define the subroutine header with one parameter: 'calcDelivery(weight)'.
    3. 3.Step 3: Implement selection logic using an IF-ELSE structure comparing 'weight' against the threshold of 5.
    4. 4.Step 4: Use the return statement within each branch to output the numerical value (£3.50 or £7.00).
    Final Answer: function calcDelivery(weight) if weight < 5 then return 3.50 else return 7.00 endif endfunction

    Question: Explain two advantages of using structured programming and subroutines when developing a large software system with a team of developers. [4 marks]

    1. 1.Step 1: Identify advantage 1 related to team workflow and modular development.
    2. 2.Step 2: Explain advantage 1: Breaking the project into subroutines allows tasks to be divided among different team members to work on independently.
    3. 3.Step 3: Identify advantage 2 related to maintenance, debugging, or reusability.
    4. 4.Step 4: Explain advantage 2: Subroutines can be tested, debugged, and reused independently without affecting the rest of the program.
    Final Answer: 1. Modular development: Breaking code into distinct subroutines allows different programmers to write and test separate modules simultaneously, accelerating development time. 2. Code reusability and easier maintenance: Subroutines can be called multiple times from different parts of the system without duplicating code; errors only need to be fixed in one subroutine rather than multiple locations.
    Active Recall Memory Test
    What is the single defining difference between a procedure and a function?
    Key Fact: A function returns a value to the calling statement, whereas a procedure does not return a value.
    Why is the use of local variables preferred over global variables in subroutines?
    Key Fact: Local variables keep data encapsulated, prevent accidental modification from other parts of the program, and release memory once the subroutine finishes.
    What is the difference between an argument and a parameter?
    Key Fact: A parameter is the placeholder variable defined in the subroutine signature; an argument is the actual value passed into the subroutine when called.
    Frequently Asked Questions
    What is the main difference between a function and a procedure?
    The primary difference lies in whether a value is returned to the line of code that called it. A function runs a block of code and always passes a value back via a 'return' statement, allowing it to be assigned to a variable or used in an expression. A procedure carries out an action, such as displaying a menu or updating an interface, but sends no data back.
    Can a procedure have parameters in AQA GCSE Computer Science?
    Yes, both procedures and functions can accept parameters. Parameters act as input channels that allow external data values (arguments) to be passed into the subroutine when it is called, ensuring the subroutine can operate on different data sets.
    Why does structured programming make debugging easier?
    Structured programming isolates code into discrete, modular subroutines. When an error occurs, developers can test each subroutine independently using specific test data. Once a subroutine is verified, it can be trusted, narrowing down the search area for bugs in the broader program.
    What happens to a local variable after a subroutine finishes running?
    When a subroutine finishes executing, its execution frame is removed from the call stack, and any local variables declared inside it are deallocated from memory. This efficient memory management is one of the main advantages of using local variables rather than global variables.