📁 Paper 1 · 3.2 Programming
3.2.11a Structured Programming
AQA 8525 · GCSE Computer Science · ~10 min read
Notes
──
Video
──
Worksheet
──
Quiz

What is Structured Programming?

Structured programming is an approach to writing programs that uses subroutines, sequence, selection, and iteration to make code easier to read, test, and maintain. It avoids uncontrolled jumps (like GOTO statements).

The three core constructs are sequence (instructions in order), selection (IF/ELSE), and iteration (loops) — together these can express any algorithm.

Local Variables

A local variable is declared inside a subroutine and only exists while that subroutine is running. It cannot be accessed from outside the subroutine.

SUBROUTINE calcArea(length, width) area ← length * width // 'area' is LOCAL — only exists inside here RETURN area ENDSUBROUTINE // This would cause an error — 'area' doesn't exist out here: // OUTPUT area

Global Variables

A global variable is declared at the top level of a program, outside any subroutine. It can be accessed by any part of the program, including from inside subroutines.

// Global variable — declared at top level highScore ← 0 SUBROUTINE updateHighScore(newScore) IF newScore > highScore THEN highScore ← newScore // Accessing the global variable ENDIF ENDSUBROUTINE

Local vs Global — Comparison

FeatureLocal VariableGlobal Variable
Declared inside/outside subroutineInside a subroutineOutside all subroutines
Accessible from where?Only inside that subroutineAnywhere in the program
LifetimeCreated when subroutine runs; destroyed when it endsExists for entire program run
Memory useReleased when subroutine endsHeld in memory the whole time
RiskLow — can't be accidentally changed elsewhereHigher — can be changed from anywhere

Scope

Scope describes where in a program a variable can be used. Local variables have local scope; global variables have global scope.

Why prefer local variables?

  • Less risk of accidentally overwriting a value elsewhere
  • Easier to test — the subroutine's behaviour depends only on its own data
  • Freed from memory when no longer needed
  • Makes subroutines truly reusable and independent

Modular Design

Modular design (also called decomposition) means splitting a large problem into smaller, manageable modules (subroutines). Each module does one specific job.

AdvantageWhy it helps
Easier to testEach module can be tested independently
Team developmentDifferent people can work on different modules
Code reuseModules can be used in other programs
Easier to debugFaults are isolated to one module
Easier to readMain program reads like a high-level description
// Modular design — main program reads clearly username ← getUsername() password ← getPassword() valid ← authenticate(username, password) IF valid THEN showDashboard() ELSE showError() ENDIF
Exam tip: If an exam question asks you to identify a local vs global variable, remember: if it's declared/assigned inside a SUBROUTINE...ENDSUBROUTINE block it is local; if it's at the top level it is global. Scope questions are very common in AQA 8525 exams.
⚠️ Common Mistakes
  • Thinking local variables persist after the subroutine ends — they do not
  • Using lots of global variables — this is poor practice and can cause hard-to-find bugs
  • Confusing parameters with local variables — parameters are also local to the subroutine
Video coming soon

Key points

  • Local variables exist only inside their subroutine; global variables exist everywhere
  • Scope = where in the program a variable can be accessed
  • Prefer local variables — safer, easier to test, less memory held
  • Modular design splits a problem into subroutines — better testing and reuse
Click slide or press arrow keys to navigate
✍️

Worksheet — 3.2.11a Structured Programming

8 questions · 18 marks

Q1Define the term 'local variable' and state where it is declared.[2]
✅ Mark scheme
Mark scheme
A local variable is a variable that can only be accessed within the subroutine it was declared in [1]; it is declared inside a subroutine [1].
Q2Define the term 'global variable' and state where it is declared.[2]
✅ Mark scheme
Mark scheme
A global variable can be accessed from anywhere in the program, including inside subroutines [1]; it is declared outside all subroutines, at the top level of the program [1].
Q3State what is meant by 'scope' in programming.[1]
✅ Mark scheme
Mark scheme
Scope is the area of a program where a variable can be accessed [1].
Q4Give two advantages of using local variables rather than global variables.[2]
✅ Mark scheme
Mark scheme
Any two from: reduced risk of accidentally changing a value [1]; memory is freed when the subroutine ends [1]; subroutine is easier to test independently [1]; makes subroutines reusable as they don't depend on global state [1].
Q5Identify which variables in the following are local and which are global: score ← 0 (top level); SUBROUTINE addPoints(pts) total ← score + pts RETURN total ENDSUBROUTINE[2]
✅ Mark scheme
Mark scheme
score is global (declared at top level) [1]; pts and total are local (inside the subroutine definition) [1].
Q6State what 'modular design' means in the context of programming.[2]
✅ Mark scheme
Mark scheme
Modular design means breaking a large program down into smaller, independent subroutines/modules [1], each of which performs one specific task [1].
Q7Give three advantages of modular design.[3]
✅ Mark scheme
Mark scheme
Any three from: easier to test each part independently [1]; modules can be reused in other programs [1]; team of programmers can work on different modules simultaneously [1]; easier to find and fix bugs (faults are isolated to one module) [1]; main program reads more clearly [1].
Q8A student writes a program with 12 global variables and no subroutines. Explain two problems this might cause.[4]
✅ Mark scheme
Mark scheme
Any two problems with explanation: (1) Any part of the program can change any global variable, so accidental overwrites are hard to track down [2]; (2) Without subroutines, code is not reusable and the same logic may be duplicated in multiple places, making maintenance harder [2]; (3) Testing is hard because you cannot test individual functions — you must run the whole program [2].
Check your answers above.
Topic Quiz
Q 1 of 10
You scored
out of 10
Card 1 of 6
Click to flip
🎉
All done!
TermDefinition
🎯

Mini Test — 3.2.11a Structured Programming

Timed exam conditions.

  • 8 questions · 10 minutes
  • 5 MCQ + 3 short answer
← 3.2.10b Parameters
22 of 57 · AQA 8525
3.2.11b Robust Programming →