Courses / Computer Science I
Programming II

Structured Program Design

Computer Science I 202 words Free to read

Building Well-Structured Programs

Once code works, the next skill is keeping it understandable as it grows. Structured programming builds programs using only three fundamental control structures:

StructureDefinition
SequenceStatements run in order
SelectionChoosing a path with if/else
IterationRepeating with loops

The structured program theorem proves these three suffice for any computation. Unrestricted jumps produce spaghetti code, an unmaintainable tangle. Structured programming ensures every block has one entrance and one exit.

Pitfall: Believing working code needs no structure. Structure is for future human understanding, not today's output.
Three bounded shapes replace an arbitrary tangle of jumps

Top-Down Design & Modularity

Good structure relies on top-down decomposition: breaking a large task into smaller sub-tasks or functions until each piece is simple. Two design virtues guide this process:

VirtueDescription
High CohesionEach unit does one well-defined thing
Low CouplingUnits depend on each other as little as possible

Together, high cohesion and low coupling let you change one part of a program without breaking others. Always measure code quality by human readability, single-entry blocks, and modularity.

Practise this lesson

The explanation above is free to read. The graded practice for this lesson lives in the Tryals app.

11practice questions
2interactive scenes

Programming II