SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
AQA 8525 · Section 3.2 · 3.2.11a

Structured
Programming

Decomposition · Modular Design · Local vs Global Variables

CSZoneAQA GCSE Computer Science 8525
What is Structured Programming?

Organising Code Properly

Structured programming means breaking a large problem into smaller, well-organised subroutines that each do one specific thing. This makes programs easier to write, test, read, and maintain.
Sequence — instructions run in order, one after another
Selection — decisions with IF and CASE OF
Iteration — repetition with loops (FOR, WHILE, REPEAT)
Subroutines — reusable named blocks of code
Local vs Global Variables

Scope of Variables

LOCAL VARIABLE
Declared inside a subroutine. Only exists while that subroutine runs. Cannot be accessed outside it.
SUBROUTINE calc()
  x ← 10 ← local
ENDSUBROUTINE
GLOBAL VARIABLE
Declared outside all subroutines. Accessible throughout the whole program. Can cause unintended changes.
score ← 0 ← global
SUBROUTINE update()
  score ← score + 1
ENDSUBROUTINE
Best practice:Use local variables where possible — global variables can be accidentally changed anywhere.
Modular Design

Breaking a Problem Down

Example: Quiz Game
Main program calls: displayMenu()askQuestion()checkAnswer()displayScore()
SUBROUTINE main()
  displayMenu()
  FOR i ← 1 TO 10
    q ← askQuestion(i)
    checkAnswer(q)
  ENDFOR
  displayScore()
ENDSUBROUTINE
Benefit:Each subroutine can be independently written, tested, and debugged by different team members.
Exam Practice

Have a go at this question

AQA-style question
Explain the difference between a local variable and a global variable, and give one benefit of using local variables.
3 marks
A local variable is declared inside a subroutine and only exists while it runs [1]. A global variable is declared outside subroutines and accessible anywhere [1]. Benefit: local variables cannot be accidentally changed by other parts of the program, reducing bugs [1].
Key Takeaways

What to Remember

Structured programming = sequence, selection, iteration, subroutines
Local = inside subroutine only · Global = whole program
Prefer local variables — safer, reduces side effects
Modular design: break program into subroutines → easier to test and maintain