What sequencing means
Sequencing is the rule that a program’s instructions run one after another, in the order they are written. The first statement finishes, then the second starts, then the third, and so on. In most procedural programming languages, this is the default control flow. Other structures, such as selection and iteration, change that flow only when the code asks them to.
Sequencing is usually the first idea a learner meets in programming, because nearly every program depends on it. Even a short script is a sequence of steps.
A simple example
Here is a short Python program with four statements:
length = 4
width = 3
area = length * width
print(area)
Python runs these lines from top to bottom, and the program prints 12. Each line finishes before the next one starts, so area already holds 12 when print runs.
The same steps in pseudocode might read:
- Set length to 4.
- Set width to 3.
- Multiply length by width and store the result in area.
- Display area.
A flowchart for the same steps is a straight line of boxes, with one arrow leading from each box to the next.
Why the order of statements matters
Because sequencing runs steps in order, changing the order can change the result. Swapping two variables is a common example:
a = 5
b = 9
a = b
b = a
print(a, b) # prints 9 9
The second assignment copies the value that a has already changed, so both variables end up as 9. A correct swap saves one value first:
a = 5
b = 9
temp = a
a = b
b = temp
print(a, b) # prints 9 5
A second kind of order problem is using a variable before it has a value. In Python, print(total) followed by total = 10 raises a NameError, because the first line runs before total exists.
Where sequence stops and other structures start
Sequence alone runs each step once, in a fixed order. Programs often need to make choices or repeat work, so most languages add other control structures:
- Selection runs different steps depending on a condition, such as an
ifstatement. For the next step after this topic, see what is selection in computer science. - Iteration repeats steps, such as a
fororwhileloop. - Jumps and function calls move the flow to another place in the code, and then the flow returns or continues.
In 1966, Corrado Böhm and Giuseppe Jacopini showed that programs can be written using only three kinds of control structure: sequence, selection, and repetition. Their result is often cited when these three ideas are introduced together.
How sequencing works in hardware
At the hardware level, a processor runs machine instructions in a repeating cycle. It fetches the instruction at the address held in the program counter, decodes it, and executes it. The program counter then moves to the next instruction in memory, unless a branch or jump changes it. For more on this, see what is the sequence in which a computer operates.
Modern processors overlap these stages and may run some instructions out of order internally. They are designed to produce the same results as if the instructions ran in program order, so the simple model still describes what a program appears to do.
Scheduling is a separate question. The order in which an operating system switches between running programs is handled by cpu scheduling algorithms, not by the sequence inside one program.
Sequencing in AP CSP
In AP Computer Science Principles, sequencing is one of three basic algorithm types, along with selection and iteration. Course materials ask students to build programs that include all three types, and to trace code that uses them. For the course-specific view, see what is sequencing in APCSP.
The College Board is revising the course framework for fall 2027. Check the current course and exam description for how sequencing is grouped in your school year.
Common mistakes
- Assuming later lines run first. Code runs top to bottom, so a value must be set before it is used.
- Treating every line as always running. A line inside an
ifblock may be skipped. That is selection, not sequence. - Changing the order without checking dependencies. Two statements that depend on each other must keep their order.
Key takeaways
- Sequencing means instructions run one after another, in the order written.
- Order changes results when statements depend on each other.
- Selection and iteration change the flow of a program. Sequence is the default.
- Processors follow the same idea through the program counter, with internal reordering that keeps results the same.