Lecture Notes — Lecture 03: Flowcharts and Control Flow

Companion to the lecture plan and the worked examples. Read the Definitions before class, the Explanation after it; the practice questions and the lecture quiz close the loop.

Definitions

Explanation

What flowcharts add over pseudocode. Termination and reachability become visible: a diamond with one exit, an arrow into a dead end, a loop whose exit condition can never be true - all obvious in a picture, easy to miss in text.

The arrow discipline. Every diamond has exactly two labelled exits. Every path from start reaches end. Nothing floats unattached. Four symbols total (terminator, process, decision, connector) - resist flowchart libraries with 20 shapes.

From words to diamonds. Each 'otherwise', 'unless', and 'until' in the requirements is a decision. Extract them first, then wire the normal path around them.

Tracing arrows = tracing state. Walk a real input through the arrows with a finger. If you cannot say which branch a concrete input takes, the flowchart (or the spec) is broken.

State machines. A vending machine is four states (idle, accepting credit, vending, sold-out) and the arrows are the events. This is the flowchart idea wearing a different hat - and it returns in cs-007 and lecture 12's clinics.

Examples

The lecture's worked examples live in examples.md; the case studies this lecture builds on are worked in class from the projector. The case sequence with difficulties:

Common misconceptions

Summary and key takeaways

  1. Four symbols, two exits per diamond, every path reaches the end.
  2. Every loop names the quantity that shrinks.
  3. Trace arrows with a real input before believing the picture.
  4. Flowcharts expose dead branches and bad termination that text hides.

Practice questions

Where this leads

Next lecture: First Python: State and Sequences. The quiz below checks this lecture's essentials before we build on them.