GCSE · Computer Science · AQA · Spec 8525

Structured approach to programming

Picture one giant block of code doing everything, with no clue where each job starts or ends. Now picture a few small, named jobs instead. Which would you rather fix?

Computer Science · Structure

One program, broken into small jobs

This is a structure chart for a program that marks a quiz. Tap each box. On the lines, ↓ means a value handed in and ↑ means a value sent back.

↑ score↓ score, total ↑ percentage↓ percentage ↑ grade

Tap any part of the diagram to see what it does.

Computer Science · Subroutines

Watch the program leave, then come back

calculate_percentage from the chart, now as real code. It is written at the top, but watch when it actually runs.

Predict first: when you reach line 6, which line do you think runs next?

1 def calculate_percentage(score, total):
2 percentage = score / total * 100
3 return percentage
4 # main program
5 mark = 15
6 result = calculate_percentage(mark, 20)
7 print(result)

Variables

Output

 

Step 1: The def line tells the program that calculate_percentage exists. The indented lines under it are skipped for now: none of that code has run.

1 / 8

Keep your eye on the highlighted line: it jumps up to the subroutine, then drops back into the main program.

Step 1 of 8: The def line tells the program that calculate_percentage exists. The indented lines under it are skipped for now: none of that code has run..

Watch out: Written at the top does not mean run first. A subroutine's code runs only when the main program calls it.

Your turn · Build an interface

From a box on the chart to a subroutine

Turn the choose_grade box into a subroutine. Pick each missing part of its interface.

  1. The box on the chart: take a percentage and decide the grade.Start from the plan. The box tells us the ONE task this subroutine does.
  2. missing step
Which line is step 2?

Unstructured code vs structured code

Unstructured (goto-style) codevsStructured code

Read across each row, then open the insight to see why it matters.

Focus

How a loop ends

Unstructured (goto-style) code

It is forced to stop part-way through, for example with a break statement.

Structured code

A while loop ends only when its condition becomes false.

The insight

Watch for this one in your own code: while True with a break inside. It works, but the loop is being stopped by the break, not by its condition, and that is exactly what structured code avoids.

Ways in and out

Unstructured (goto-style) code

A section can be jumped into or out of at many different points.

Structured code

One entry point and one exit point.

How control moves

Unstructured (goto-style) code

goto statements jump to another line, forwards or backwards.

Structured code

Only three structures: sequence, selection (if, elif, else) and iteration (while and for loops).

Following the code

Unstructured (goto-style) code

Overusing goto makes the code messy and hard to follow. This is called spaghetti code.

Structured code

Much easier to follow, one structure at a time.

Computer Science · Why bother?

Spot the advantage

A team is building the quiz marker. Each moment below shows one advantage of the structured approach. Put each one under the advantage it shows.

Still to sort

Easier to read and understand (0)

The code is split into small, manageable sections.

Easier to test (0)

Each subroutine carries out one task, so errors are easier to find and fix.

Where the line is: Testing is about FINDING and fixing a fault. Maintenance is about making a change later without breaking the rest.

Easier to maintain (0)

A change is made and tested in one place without affecting the rest of the program.

Where the line is: If the program is being changed on purpose, not hunted for a bug, it is maintenance.

Faster development (0)

Several programmers can work on different subroutines at the same time.

Where the line is: Faster development is about PEOPLE working in parallel, not about one subroutine being used again.

Reuse (0)

A subroutine can be called many times, so the same code is not written out again.

Where the line is: Reuse is about CALLING the same subroutine again, not about sharing the work out.

6 of 6 still to sort.

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

Split one big job into small named jobs, plan them on a chart, and call each one when you need it.

What you need to know

  • A structured approach decomposes a program into smaller subroutines, each designed to do one specific task.
  • A subroutine is a named sequence of instructions that performs a specific task. It is out-of-line code: it runs only when it is called.
  • Before coding, subroutines are planned on a structure chart: the main program at the top, the subroutines beneath it.
  • Each subroutine's interface is its identifier, its parameters (values passed in) and its return value (value passed back).
  • Structured code uses sequence, selection and iteration instead of goto, and has one entry point and one exit point.

The big picture

The structured approach breaks a program into small subroutines that each do one specific task. They are planned on a structure chart, each has a clear interface (identifier, parameters, return value), and they run only when the main program calls them. Structured code uses sequence, selection and iteration instead of goto, and has one entry point and one exit point. This makes programs easier to read, test and maintain, faster to develop, and lets code be reused.

Key points

1Decompose: one big program becomes several small subroutines, each doing ONE task, which makes a growing program manageable.
2A subroutine is often written at the top of a program but does not run first. The program does not simply run from top to bottom: control jumps to a subroutine when it is called and returns afterwards.
3A structure chart (hierarchy diagram) shows the plan: the top box is the main program, and the boxes beneath are the subroutines it is broken into.
4An interface decides how data gets in and out: a meaningful identifier, the parameters that must be passed in, and the return value passed back to the main program.
5Overusing goto gives messy, hard-to-follow spaghetti code. Structured code uses sequence, selection (if, elif, else) and iteration (while, for) instead.
6One entry, one exit: a while loop should end because its condition becomes false, not because a break forces it to stop.
7Advantages: easier to read, easier to test, easier to maintain, faster to develop (several programmers at once) and less repeated code (a subroutine can be called many times).

Worked example

Problem

This loop keeps asking for a password until the right one is typed: while True: guess = input("Password: ") if guess == "open123": break Explain why the loop is not properly structured, then rewrite it so that it is.

⚠ Watch out

Thinking a program runs from top to bottom, so the subroutine written at the top runs first. It does not: a subroutine is out-of-line code that runs only when the main program calls it, and then control comes back to the line that made the call.

🧠

Memory hook

Plan it like a family tree, run it like a phone call. The chart shows who belongs under whom; when the program runs, main rings a subroutine, hands over the details, waits, and gets an answer back before carrying on.

✓

Check yourself

Cover the page. Name the three parts of a subroutine's interface and say which one carries a value back. Then say why while True with a break inside is not properly structured.

Flashcards

(14)
What is the structured approach to programming?
A modular approach: the program is decomposed into smaller subroutines, each designed to do one specific task, so a growing program stays manageable.
What is a subroutine?
A named sequence of instructions that performs a specific task.
What does 'out of line' mean for a subroutine?
Its code sits apart from the main program (often at the top) and runs only when it is called.
A subroutine is written at the top of a program. Does it run first?
No. The program starts its work in the main program, and the subroutine runs only when it is called, before control returns to the calling line.
On a structure chart, what does the top box show? What do the boxes beneath it show?
Top: the main program. Beneath: the subroutines it is broken into.
When is a structure chart drawn?
Before coding, to plan the subroutines and decide how they relate to each other.
What does a subroutine's interface determine?
How data is passed into and out of the subroutine.
Interface: what is the identifier?
The subroutine's name. It should be meaningful, so it says what the subroutine does.
Interface: what are the parameters?
The values that must be passed in to the subroutine.
Interface: what is the return value?
The value the subroutine passes back to the main program.
Which three structures control the flow in structured programming?
Sequence, selection (if, elif, else) and iteration (while and for loops), used instead of goto.
What is spaghetti code?
Code made messy and hard to follow by overusing goto statements.
How many entry and exit points does a properly structured program have?
One entry point and one exit point. For example, a while loop ends when its condition becomes false, not with a break.
Five advantages of the structured approach?
Easier to read, easier to test, easier to maintain, faster development (programmers work in parallel) and reuse (call a subroutine many times instead of repeating code).

Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.

Learning with Lightbulb is opening soon

You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.

Keep me posted

More AQA GCSE Computer Science topics

See the full AQA Computer Science curriculum →

How this lesson was checked. This AQA GCSE Computer Science (specification 8525)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 30 September 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.