Home · Academy · Robotics & Coding · Algorithms · Sequence: The Right Order of Commands

Sequence: The Right Order of Commands

Sequence decides the order in which the commands of an algorithm run so they produce the correct result.

LESSON COMPASS

What will you use this page for?

Core idea

Sequence is what decides the order in which the commands in an algorithm run, so that they lead to the correct result.

Evidence to produce

Complete the page task with your own input, test conditions and reasoning.

Control trap

Not stating the starting state. Producing the data a step needs only later on. Leaving broad steps like "get ready" or "check" far too vague. Doing the safety check after the physical movement instead of before. Forgetting the finish or stop step.

Next connection

Conditions: If, Else and Making Decisions

Module sources: Python Tutorial · Arduino Learn

LevelBeginner
Age10–16
Duration25–35 min
PrerequisiteWhat Is an Algorithm?
ContentStandard lesson · 1,389 words
Last updated

One-sentence summary

Sequence is what decides the order in which the commands in an algorithm run, so that they lead to the correct result.

Why it matters

Running the same commands in a different order can give a different result. Trying to tie a shoe first and then put it on is a good example of using the right steps in the wrong order. Computers and robots usually run commands in the order we write them, so the place of each step really matters.

What is sequence?

The order in which an algorithm moves from its first command to its last is called sequence. Even the simplest programs follow an order:

Start
Get the user's name
Print "Hello"
Print the name
End

If we remove the second step, or try to print the name before we have asked for it, the information the program needs does not exist yet.

Daily life example: Making a sandwich

The right order:

  1. Wash your hands.
  2. Get the bread ready.
  3. Add the fillings.
  4. Close the sandwich.
  5. Put the ingredients back where they belong.

If we close the sandwich before adding the fillings, we do not get the result we wanted.

Robot example: Reaching a target

At the start, the robot is facing north, and the target is to its east.

Turn right
Move forward 3 squares
Stop

If we swap the commands like this:

Move forward 3 squares
Turn right
Stop

the robot does not reach the target. It first moves north, and only then turns to face east.

Code example

Let's work out the average of two numbers in Python:

first = 8
second = 12
total = first + second
average = total / 2
print(average)

Before average can be worked out, total has to exist first. The way information flows from one command to the next is what sets the sequence.

Thinking about dependencies

If one step needs the result of another step before it can run, there is a dependency between those two steps.

Examples:

When you write an algorithm, ask yourself one question:

Which piece of information, or which step, must already be finished before this step can work?

Work that can happen in parallel

Not every task has to happen in a single line, one after another. In some systems, jobs that do not depend on each other can run at the same time. For example, a robot's LED can blink while the robot is moving. Even so, at a beginner level it is better to build one clear, safe sequence first, and to think about parallel behaviour later.

Mini activity: Checking before a bike ride

Put the steps below into a safe order:

Example solution:

1. Choose a safe route
2. Put on your helmet
3. Check the tyres
4. Check the brakes
5. If something is wrong, ask an adult for help
6. If everything is safe, start riding

Here it is not only the order that matters, but the safety condition too.

A method for debugging the order

To find a sequencing mistake:

  1. Write down the result you expect.
  2. Note the state of the system after each step.
  3. Find the first step where something unexpected happens.
  4. Check whether the information that step needs was created earlier.
  5. Fix the order and test again.

Practice lab: Sequence: The Right Order of Commands

The best way to retain Sequence: The Right Order of Commands is to turn the idea into a small, measurable task. In this activity you will connect What is sequence? with Robot example: Reaching a target and produce a clear algorithm, pseudocode and a test table. The aim is not only to make the result work. You should also be able to explain why you made each decision, what you tested and which observation would make you revise the design.

Challenge scenario

Work with this scenario: a small planner that orders daily tasks by priority. Because the main goal of the lesson is to “Sequence decides the order in which the commands of an algorithm run so they produce the correct result”, begin by defining the problem in one sentence. Then write the input, the process and the output separately. Mark anything you do not know as an assumption rather than presenting it as a fact.

  1. Plan: Record the starting state, expected result and the concepts you will use.
  2. Build the smallest version: Make only the essential behaviour work before adding decoration or extra features.
  3. Prepare three tests: Choose a normal case, a boundary case and an invalid or unexpected case.
  4. Record the result: Put the expected and actual results side by side and name a likely cause when they differ.
  5. Change one thing: Revise one decision and repeat the test instead of changing several parts at once.

Success criteria

After completing “Sequence: The Right Order of Commands”, explain the work to a classmate using only the section headings. If the classmate can follow the decisions in the scenario of a small planner that orders daily tasks by priority, the explanation is clear enough. Fix an unclear point by dividing the relationship between What is sequence? and Robot example: Reaching a target into smaller steps rather than adding jargon.

Common mistakes

Safety note

Some of the examples here involve real, moving things, such as robots and bikes. When you try physical steps, run the safety checks before anything starts to move, and do the activity together with an adult. In a beginner project, a clear order is also a safer one.

Lesson summary

Check questions

  1. Why does sequence matter?
  2. What does it mean for one step to depend on another?
  3. In the robot example, why did moving first and turning afterwards give the wrong result?
  4. In a physical project, at which stage should the safety check happen?
  5. Write a four-step algorithm from your own daily life whose result breaks if the order changes.

Answers and explanations

  1. Because computers and robots usually run commands in the order we write them. A different order can therefore lead to a different result.
  2. It means the second step needs the result of the first step before it can run, so the information it depends on has to be created first.
  3. Because the robot started out facing north. Moving before turning sent it north instead of east, so it ended up in the wrong place.
  4. Before any physical movement starts, so that a problem is caught while everything is still safe.
  5. This is an open question, so answers will vary. A good answer lists four steps where changing the order clearly changes the outcome — for example, making tea: boil the water, add the tea, let it steep, then pour. There is no single correct list.

Source and verification note

For “Sequence: The Right Order of Commands”, verification focuses on whether the relationship between What is sequence? and Robot example: Reaching a target remains consistent across examples. The algorithms in this lesson are checked by tracing sample inputs by hand and comparing them with expected outputs. Pseudocode is used to make the reasoning sequence visible without tying it to one programming language.

Next lesson

Conditions: If, Else and Making Decisions

Start QuizBack to Algorithms
QUESTION POOL

Reinforce this lesson with 10 questions

This lesson has a pool of 20 questions. Each attempt selects 10 and reshuffles the choices.