GCSE · Computer Science · AQA · Spec 8525

Structured approach to programming

Something's broken. One giant block of code doing everything, or a handful of small, named jobs: which would you rather fix?

Computer Science · Structure

One program, broken into small jobs

A structure chart for a program that marks a quiz. Tap each box to see its one task and its interface. On the lines, ↓ is a value handed in and ↑ is 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's written at the top. 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

This is the one people mix up. A loop with a break inside still works, so it looks fine. It isn't structured: the break is doing the stopping, not the condition.

Ways in and out

Unstructured (goto-style) code

A loop with a break inside has a way out other than its condition, so it is not one exit point.

Structured code

One entry point and one exit point.

How control moves

Unstructured (goto-style) code

goto statements jump to another line.

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?

Which advantage is this?

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's 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 isn't 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

  • Big program? Break it into smaller subroutines, each designed to do one specific task.
  • Small single-task pieces are easier to solve on their own, so a growing program stays manageable.
  • A subroutine is a named sequence of instructions that performs a specific task.
  • It's out-of-line code: often written at the top, yet it runs only when the main program calls it.
  • Have a goPriya writes a perfect subroutine called make_toast at the very top of her program. Her main program never calls it. How many slices get toasted?

    None. The make_toast code never runs.

    Being written at the top doesn't make it run. Out-of-line code waits for a call, and here nobody ever makes one, however good the subroutine is.

  • Plan before you code: a structure chart puts the main program in the top box, its subroutines beneath.
  • Each interface sets how data gets in and out: a meaningful identifier, parameters passed in, a return value passed back.
  • Have a gofind_max(a, b) hands back whichever of its two numbers is bigger. Which part of its interface are a and b, and which part is the bigger number?

    a and b are the parameters; the bigger number is the return value.

    The tempting slip is to call a and b the return value. They go IN through the brackets; only the result comes back OUT.

  • Structured code steers the flow with sequence, selection (if, elif, else) and iteration (while, for), not goto.
  • Overuse goto and the code turns messy and hard to follow. That tangle is called spaghetti code.
  • One entry, one exit: a while loop should stop because its condition turns false, not because a break forces it.
  • Have a goA game loop runs while lives > 0, and you lose one life each time round. There's no break anywhere. So what actually ends the game?

    The condition turns false when lives reaches 0.

    No break needed. In structured code a loop's one exit is its condition becoming false, which is exactly what happens here.

  • The payoff: easier to read, test and maintain, faster to develop, and less repeated code.

The big picture

The structured approach breaks a program into small subroutines that each do one specific task. You plan them on a structure chart, give each one a clear interface (identifier, parameters, return value), and they run only when the main program calls them. Structured code steers the flow with sequence, selection and iteration instead of goto, and has one entry point and one exit point. The payoff: programs that are easier to read, test and maintain, faster to develop, and less full of repeated code.

Key points

1Decompose: one big program becomes several small subroutines, each doing ONE task, which makes a growing program manageable.
2Written at the top does not mean run first. The program doesn't simply run from top to bottom: control jumps to a subroutine when it is called and comes back 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 must run first. Feels obvious. It's wrong: 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 sits 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 October 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.