1.Why should I care?
Flowcharts are how engineers sketch the logic of a controller before it becomes code. A five-minute trace on paper can reveal a loop that never ends, which on a real pump means a flooded floor.
- ◇ Read and draw a flowchart with actions, a decision and a loop back.
- ◇ Trace a flowchart by hand with a trace table to predict how many times a loop runs.
- ◇ Explain why a loop's stopping test should use < or >= rather than an exact match.
2.Discover
Start at 20 L with the decision 'level < 90'. Predict how many times the pump runs, then press Step and fill in the trace table. Now switch to 'level != 90' and run it again. Try a start of 30 L too: why does != work there but not from 20 L?
Loading the interactive…
Can't use the interactive? Read a description instead
The flowchart runner shows: Start (read level) → decision 'level < 90?' → if yes, pump one pass adding 15 L and return to the decision; if no, pump off and stop. A slider sets the starting level and a switch changes the decision to 'level != 90'. From 20 L the trace table reads 20, 35, 50, 65, 80, 95 (stop) with '<', but with '!=' the levels pass 90 and keep rising past the 120 L tank capacity.
3.Checkpoint: guided practice
Check what you just discovered before going on. Hints appear after a wrong answer.
Practice 1 · a fresh version every time
A tank starts with 55 L of water. The controller runs: while level < 100: level = level + 10 (one pump pass adds 10 L). How many times does the pump run before the loop stops?
Practice 2
In a flowchart, what does a diamond mean?
4.Predict
The tank starts at 20 L and each pump pass adds 15 L. The flowchart loops while level != 90. What happens?
Guess first. Being wrong here is how the surprise works.
5.Understand
Three shapes are enough
Rounded boxes mark start and end. Rectangles are actions (pump on for one pass). Diamonds are decisions with exactly two exits, yes and no. Arrows say what happens next. An arrow that leads back up to an earlier decision makes a loop.
Trace tables catch bugs on paper
A trace table has one row each time you reach the decision: the value of every variable and whether the test is true. Tracing 20, 35, 50, 65, 80, 95 by hand shows exactly when the loop stops, before any pump is wired up.
Stop on a range, not an exact value
Real quantities rarely land exactly on a target. Steps of 15 L skip over 90 L; a sensor reading of 89.97 is not 90. A stopping test such as level < 90 (keep going while below) always ends; level != 90 can run for ever. Engineers also add a safety limit, such as a maximum number of passes or a high-level float switch.
Explain it another way
Imagine filling a bath with a jug that holds 15 L and stopping only when the water is at exactly the 90 L line. You would pour past it and keep going, because 'exactly' never happens.
A flowchart is a directed graph of process and decision nodes. A loop is a cycle in that graph; it terminates only if the condition on its exit edge must eventually become true. Inequality tests guarantee that for a level that only increases; equality tests do not.
Passes n = ⌈(T − S)/A⌉ for S < T, otherwise 0. Final level = S + n·A, which lies in the range [T, T + A).
Industrial tanks combine a level sensor with an independent high-level switch that cuts the pump regardless of the controller. Overflow protection is a requirement, not an optional extra.
Derivation: How many passes does the loop need?
The loop runs while
level < target. Start level S, each pass adds A litres.After n passes the level is S + n·A. The loop stops at the first n where S + n·A ≥ target.
Rearrange: n·A ≥ target − S, so n ≥ (target − S) / A.
n must be a whole number of passes, so n is (target − S) / A rounded up. From 20 L with A = 15 L and target 90 L: (90 − 20) / 15 = 4.67 → 5 passes, finishing at 20 + 5 × 15 = 95 L.
If S is already ≥ target, the condition is false at the first check and the pump runs 0 times.
Worked example 1
Start 40 L, add 25 L per pass, loop while level < 120. Trace it.
40 (True) → 65 (True) → 90 (True) → 115 (True) → 140 (False, stop). The pump runs 4 times and the tank ends at 140 L. Check: (120 − 40) / 25 = 3.2 → rounded up = 4.
Common mix-ups
- If a loop condition looks sensible, the loop must end.
✓ Only trace tables, or reasoning about how the variable changes, show that it ends. Exact-match tests are a classic trap. - Flowcharts are only for beginners.
✓ Engineers still sketch flowcharts and state diagrams to agree on logic before writing safety-critical code.
6.Watch
→ Watch how a sorting algorithm repeats the same few steps with a decision each time: the same loop-and-decide shape as the tank flowchart.
Shows how a step-by-step recipe of decisions and repeats lets a machine solve a problem such as sorting.
Length: see YouTube · captions on YouTube · source
Nothing loads from YouTube until you press play.
The video is optional: everything you need is also in the lesson text and the interactive.
7.Practice on your own
Practice, not a test. Wrong answers get a hint and another try.
Practice 3
A loop runs while level != 100 and adds 30 L per pass, starting at 0 L. What happens?
Practice 4
Start at 10 L, add 20 L per pass, loop while level < 75. How many passes does the pump make?
Practice 5
Why add 'or 20 passes have run' to the tank loop?
8.Apply it
Draw a flowchart for a phone charger that charges in 10 % steps while the battery is below 80 %, then stops. Trace it from 35 %. Then redraw it with an extra decision that stops charging if the battery is hotter than 45 °C.
9.Reflect
Concepts: Decomposition, algorithms and flowcharts · Decisions and loops