Theory
Two sets of class notes
Two toppers lend you their notes before the exam.
Notebook one reads top to bottom: headings, numbered points, done.
Notebook two is a maze: "see page 12", page 12 says "continue from page 3, unless you came from page 7". Every line points somewhere else. Ten minutes in, you are lost.
Early programs were notebook two, and planes and payrolls ran on them. The cleanup that followed is called structured programming, and C was built to enforce it.
Theory
Spaghetti vs a well-bound book
Code full of arbitrary jumps was nicknamed spaghetti code: pull one strand and twenty others move, because goto statements criss-cross the program like noodles in a bowl. A structured program is the well-bound book: chapters (functions), sections (blocks), each read top to bottom, one entrance, one exit. You can open chapter 5 and understand it without unrolling the whole bowl.
Theory
The three shapes, formally
Structured programming's claim, proven mathematically in 1966: any program logic can be built from three structures:
- Sequence: statements one after another, in order.
- Selection: choose a path by a condition (
if,if-else,switch). - Iteration: repeat while a condition holds (
while,do-while,for).
Everything nests inside blocks { } and functions, each with a single entry and a single exit. No wild jumping. C gives you exactly these tools, which is why it is called a structured language.
At a glance
The three control structures
| Structure | Question it answers | C constructs |
|---|---|---|
| Sequence | What happens next? | Statements, one per line |
| Selection | Which path do we take? | if, if-else, switch |
| Iteration | How many times? | while, do-while, for |
Quiz
Which of these is NOT one of the three structured-programming control structures?
- Arbitrary jumping (goto)
- Sequence
- Selection
- Iteration
Show the answer
Arbitrary jumping (goto)
Structured programming exists precisely to REPLACE arbitrary goto jumps with the disciplined three: sequence, selection, iteration. C still keeps a goto keyword for rare emergencies (you will meet it in Unit 2), but the whole point of the discipline is to almost never need it.
Think first
Preview your own program
Think ahead for the marks program: printing a student's name, then deciding pass or fail, then processing all 60 students of the class. Which of the three structures will each part use?
Show the answer
Printing lines in order: sequence (that is all the program has today). Pass or fail: selection, the if-else you will write in Unit 2. All 60 students: iteration, the loops right after. The entire subject's roadmap is literally the three structures, taught in order. That is not a coincidence; that is the syllabus following the theory.
Watch out
Where marks leak
Confusing structured with object-oriented: C is structured, not OOP; classes and objects belong to C++/Java in later semesters, and mixing the two terms in a definition costs marks. Second leak: naming the three structures vaguely ("loops and stuff"). Learn the trio as sequence, selection, iteration with one C construct each, that exact wording earns the definition marks.
Theory
Why this discipline pays your salary
Structured code is not aesthetics: it is why a teammate can fix your function without reading your whole program, why testers can test blocks in isolation, and why million-line systems are maintainable at all. Every code review you will ever sit in is quietly asking "is this structured?". The next lesson names the tools that take such code and make it run: editor, compiler, interpreter.
Summary
Key takeaways
- Structured programming builds all logic from three structures: sequence, selection, iteration.
- Code organises into blocks and functions with single entry and single exit.
- Arbitrary goto jumps create spaghetti code; the discipline exists to avoid them.
- C is a structured language; structured is NOT the same as object-oriented.
- Benefits: top-to-bottom readability, isolated testing, teamwork.
- Memory hook: sequence, selection, iteration, the only three shapes you need.