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?

Link 1 of 4

First link · your turn

Before structured programming, what were go-to statements used for?

2
Locked — reveal the link above first
3
Locked — reveal the link above first
4
Locked — reveal the link above first

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_days
3 return total_walks
4 def charge(walks_done):
5 total_charge = walks_done * 4
6 return total_charge
7 walks = num_walks(2, 10)
8 bill = charge(walks)
total_dogstotal_daystotal_walkswalksbill
210

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.

1 / 6

Press Next to step through. Before each step, guess what the table will show.

Step 1 of 6: The main program calls num_walks(2, 10). The 2 and the 10 arrive in the parameters total_dogs and total_days..

Watch out: total_walks is a variable inside num_walks. The main program only gets that value because num_walks returns it.

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?

6 of 6 still to sort.

Computer Science · Structured programming

One line breaks the rules

This loop adds 5 to total until total reaches 20. One line deviates from structured programming. Which one?

A student's program — which line goes wrong?

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

1Structured programming uses selection, loops and subprograms instead of go-to statements.
2A structure chart puts the main program at the top and its subprograms below it.
3A subprogram's interface is its identifier, its parameters and its return value.
4The main program can only use a variable from a subprogram if it is returned.
5One entry point and one exit point: a while loop should end only when its condition evaluates to False.

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?
Messy, hard-to-follow code made by using too many go-to statements.
What were go-to statements used for before structured programming?
To repeat sections of code.
Which statements does structured programming use to control the flow of a program?
Selection statements (if, elif, else) and loops (while, for).
What is a subprogram?
A smaller section of a program designed to do one specific task. It is also called a subroutine.
What does a structure chart show?
The hierarchy of a program: the top box is the main program and the other boxes are the subprograms within it.
What three parts make up a subprogram's interface?
The identifier, the parameters and the return value.
What is an identifier?
A meaningful name for a variable or subprogram, such as num_walks.
What are parameters?
Variables that allow values to be passed into a subprogram, such as total_dogs and total_days.
What is a return value?
The value passed back to the main program, such as total_walks. A subprogram such as invoice may have none.
How do you define a subprogram in Python?
Write def, then the interface, then a colon, then an indented block of code.
When can the main program use a variable from a subprogram?
Only if the subprogram returns it, by writing return followed by the variable name.
What are the four benefits of the structured approach?
Code readability, easier testing, easier maintenance and faster development time.
Does the structured approach reduce coding errors?
No, but it can make them easier to find.
In structured programming, what should end a while loop?
Only its condition evaluating to False. Ending it with break is a deviation from one entry point and one exit point.

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 Edexcel GCSE Computer Science topics

See the full Edexcel Computer Science curriculum →

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.