Order matters
A lift opens its doors, then moves to floor 7. Every step was correct. Why is everyone screaming?
About 25 min · 3 goals · Checked by automated tests; not yet reviewed by an educator
1.Why should I care?
In real machines the order of steps is often a matter of safety. A lift must close its doors before it moves; a washing machine must drain before it unlocks. Engineers spend a lot of time asking 'what has to be true before this step is allowed?'
- ◇ Explain that the same steps in a different order can give a different result.
- ◇ Put the stages of a real machine's routine in a safe order.
- ◇ Identify which steps must come before which others.
2.Predict
A robot runs 'Turn right, then Forward 2' from (0, 0) facing north. A second robot runs 'Forward 2, then Turn right'. Do they end up in the same square?
Guess first. Being wrong here is how the surprise works.
3.Discover
Watch a lift trip, then put the seven stages of a trip in order. For each stage, ask: what must already have happened before this is safe?
Can't use the interactive? Read a description instead
The lift activity can be replaced by this description: a lift has a counterweight (balances the cabin), a door-edge sensor (detects anything in the doorway), a floor position sensor (where the cabin is), a load-weighing sensor (how heavy it is) and a motor with a pulley (turns the ropes). A trip goes: call registered, doors close, accelerate, cruise, slow down, level, doors open.
4.Understand
A sequence is steps in order
A sequence is the simplest kind of algorithm: do this, then this, then this. Most programs are mostly sequences, with decisions and loops mixed in.
Swapping steps can change everything
Some steps don't care about order: putting on your left sock or right sock first. Others do: socks before shoes. Turning before or after moving sends a robot to a completely different place.
Before-and-after rules
Engineers write down which steps must come before others: 'doors closed before the lift moves', 'drain before unlock'. Any order that breaks one of these rules is unsafe, even if every individual step is fine.
Explain it another way
Baking a cake: mix, then bake, then ice. Ice, then bake, then mix gives you a disaster made of exactly the same ingredients.
Operations that change the system's state usually do not commute: doing A then B gives a different state from B then A. Engineers record ordering constraints as 'A must happen before B'.
Lift controllers use interlocks: the motor physically cannot be powered until the door-closed sensor confirms the doors are shut. The order is enforced by the design, not just by the program.
Worked example 1
Put these lift stages in a safe order: accelerate, doors open, call registered, level with the floor, doors close, cruise, slow down.
Call registered → doors close → accelerate → cruise → slow down → level with the floor → doors open. The key rules: doors must close before any movement, and must not open until the cabin is level.
Common mix-ups
- If every step is correct, the program is correct.
✓ Correct steps in the wrong order can be wrong, or dangerous. - Turning moves the robot.
✓ A turn only changes which way it faces. Its position stays the same.
5.Practice
Practice, not a test. Wrong answers get a hint and another try.
Practice 1
Which pair of steps can safely be done in either order?
Practice 2
A robot at (0, 0) faces north. It runs: Turn right, Forward 1, Forward 1. Where does it end?
Practice 3
What must happen before a washing machine's door is allowed to unlock?
Practice 4 · a fresh version every time
A robot starts at (0, 0) facing north on an open grid (east is +x, north is +y). It runs: turn left, turn left, turn right, forward 1, turn left, forward 1. What is its final x (east–west) coordinate? Use a negative number for west.
6.Apply it
Write the steps for a robot that makes a cup of squash (fetch cup, add squash, add water, stir, serve). Which steps can swap places, and which must never swap? Write one 'must happen before' rule.
7.Reflect
Concepts: Algorithms, searching and complexity · Super-loops and finite state machines