GCSE · Computer Science · Edexcel · Spec 1CP2
Structural components of programs
A dog walker's weekly invoice is a nightmare as one tangle, and easy once it's split into small boxes with one job each.
Computer Science · Structure
A dog walker's weekly invoice, as a structure chart
Tap a box to see its one job and its interface. The names and numbers are made up for this example.
Tap any part of the diagram to see what it does.
Why structure?
Reason it through
So why did programmers move away from go-to statements?
First link · your turn
Before structured programming, what were go-to statements used for?
Computer Science · Subprograms
Follow the numbers through num_walks and charge
Values go IN through parameters and come OUT through return. Step through and watch where they go.
What will walks hold once num_walks has finished?
1 def num_walks(total_dogs, total_days):2 total_walks = total_dogs * total_days3 return total_walks4 def charge(walks_done):5 total_charge = walks_done * 46 return total_charge7 walks = num_walks(2, 10)8 bill = charge(walks)
| total_dogs | total_days | total_walks | walks | bill |
|---|---|---|---|---|
| 2 | 10 |
Output
Step 1: The main program calls num_walks(2, 10). The 2 and the 10 arrive in the parameters total_dogs and total_days.
Press Next to step through. Before each step, guess what the table will show.
Computer Science · Structured programming
Which benefit is this?
Sort each situation from the dog-walking program into the benefit of the structured approach that it shows. One category is a trap.
Still to sort
Code readability (0)
Small chunks are easier to read and check.
Easier testing (0)
A subprogram carrying out a single task is easier to test and fix.
Easier maintenance (0)
A change can be made and tested in one place without affecting the rest of the program.
Faster development time (0)
Several programmers can develop subprograms at the same time.
Fewer coding errors are written (0)
Does structuring a program really do this?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Break a big program into small boxes, each with one job
What you need to know
- Go-to statements were used to repeat sections of code, and too many made messy code called spaghetti code.
Have a goYour mate says spaghetti code is code so full of bugs that it won't run. What does the term really mean, and what causes it?
Messy, hard-to-follow code, caused by too many go-to statements.
Spaghetti is about the tangle: too many go-to statements make code messy and hard to follow, which is not the same as broken.
- Structured programming controls flow with selection (if, elif, else) and loops (while, for) instead.
- Subprograms (also called subroutines) each do one specific task, and can be called many times to cut repeated code.
Have a goA subprogram gets called three times in one program. How many copies of its code does the program need?
One. Each call just runs that one copy again.
Calling a subprogram many times doesn't mean copying it, which is how subprograms reduce repeated code.
- Plan the hierarchy with a structure chart: the main program is the top box, the subprograms sit below.
- An interface says how a subprogram talks to the main program: identifier (its name), parameters (values in), return value (passed back).
Have a goIn def num_walks(total_dogs, total_days): which part is the identifier, and which are the parameters?
num_walks is the identifier; total_dogs and total_days are the parameters.
The identifier is the subprogram's name. The parameters are the values passed in, so the name is not a parameter.
- Some subprograms, such as invoice, have no return value; the main program can only use a subprogram's variable if it is returned.
- To define a subprogram in Python, write def, then the interface, then a colon, then an indented block of code.
- The structured approach makes code easier to read, test and maintain, and faster to develop.
- Structuring doesn't reduce coding errors, though it can make errors easier to find.
- Properly structured programs have one entry point and one exit point; a while loop should end only when its condition evaluates to False.
The big picture
Structured programming replaced messy go-to statements with selection, loops and subprograms. A structure chart plans the subprograms, each with an interface (identifier, parameters, return value), and a properly structured program has one entry point and one exit point.
Key points
Worked example
Problem
Write a Python subprogram called invoice. It is given total_charge and has no return value. Then call it from the main program with a charge of 80.
⚠ Watch out
Thinking subprograms mean you write fewer errors. They don't. They make code easier to read, test and maintain, and errors easier to find.
Memory hook
Spaghetti is what go-to makes; structure is the fix. And for an interface, think name, in, out: identifier, parameters, return.
Check yourself
From memory: which box sits at the top of the dog-walking structure chart, and which subprogram has no return value?
Flashcards
(14)What is spaghetti code?
What were go-to statements used for before structured programming?
Which statements does structured programming use to control the flow of a program?
What is a subprogram?
What does a structure chart show?
What three parts make up a subprogram's interface?
What is an identifier?
What are parameters?
What is a return value?
How do you define a subprogram in Python?
When can the main program use a variable from a subprogram?
What are the four benefits of the structured approach?
Does the structured approach reduce coding errors?
In structured programming, what should end a while loop?
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 postedMore Edexcel GCSE Computer Science topics
- Programming arithmetic operators
- Programming logical operators
- Programming relational operators
- Reading, writing, analysing and refining programs
- Single entry/exit code blocks
- String manipulation
- Structured data types
- User input handling
- Validation – length check
- Validation – presence check
- Validation – range check
- Variables and constants in programs
How this lesson was checked. This Edexcel GCSE Computer Science (specification 1CP2)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 21 November 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.