Sequencing

What Is Sequencing in Programming?

Sequencing in programming means each statement runs in turn, top to bottom. See a simple Python trace, why order changes results, and common beginner mistakes.

On this page
  1. The short answer
  2. A worked example
  3. Why the order of lines matters
  4. Sequence in pseudocode and flowcharts
  5. When the order changes
  6. Common beginner mistakes
  7. Summary

The short answer

Sequencing in programming means each statement runs in turn, from the top of the program to the bottom. A statement finishes before the next one starts. Unless a control structure changes the flow, the program does not skip ahead or go back.

A worked example

Consider this Python program:

name = "Sam"
score = 42
score = score + 8
print(name, "scored", score)

Trace it one line at a time:

Step Statement Values after the step
1 name = "Sam" name is "Sam"
2 score = 42 score is 42
3 score = score + 8 score is 50
4 print(...) Prints Sam scored 50

Each row depends on the rows above it. Line 3 uses the value of score that line 2 set. That dependence is why the order matters.

Why the order of lines matters

Suppose the line that adds 8 came before the line that sets score. Python would stop with a NameError, because score would not exist yet. The same lines in a different order can produce an error or a different result.

Sequence in pseudocode and flowcharts

Pseudocode and flowcharts show the same idea. In pseudocode, steps are numbered or listed in the order they happen. In a flowchart, boxes connect with arrows in that same order. A purely sequential flowchart is a straight path with no branches.

When the order changes

Sequencing is the default, but programs often need to choose between paths or repeat steps. Those are selection and iteration. For the choice case, see what is selection in computer science. For the bigger picture of how these structures fit together, see what is sequencing in computer science.

Common beginner mistakes

  • Using a variable before it has been assigned a value.
  • Expecting a line inside an if block to run when the condition is false.
  • Reading a program as a whole instead of line by line, which hides which value each line actually sees.

Summary

Sequencing means running statements one at a time, in the order they are written. Tracing a program line by line, and noting the value of each variable after each step, is a reliable way to see what the program does.

The complete guide to sequencing

What Is Sequencing in Computer Science?
Read the guide

Keep exploring

Guides from other topics

All topics →

Big O for Data Structures

A practical guide to Big O for data structures: how arrays, lists, hash tables, trees and heaps compare on search, insert and delete costs, with examples.

Big O Notation 5 min read