
Let’s think it through · Start with a story
The robot puts on its shoes before its socks. The girl laughs: both steps are right, but the order is wrong. Programs care about order, too.
Break down the process
- Startscore is 3
- Add firstscore becomes 5
- Display nextThe screen shows 5
Sequential execution means statements happen in a defined order, and later statements can see changes made earlier.
If the program displays the score before adding points, the screen shows the old score. Decisions, loops, and function calls can change where execution goes next.
01Why does code have an order?
Look at this simple program:
int a = 3;
int b = 5;
int c = a + b;
std::cout << c;
Unless the program encounters a structure that changes control flow—such as a condition, loop, or function call—it usually continues through statements in order.
02What does “the current line” mean?
When learning to read a program, imagine an “execution pointer” moving through the code to help you see what might happen next.
But this “pointer” is only a teaching model. There is no literal arrow moving across the source code inside the CPU.
03Is one line of C++ one CPU instruction?
No. One line of C++ may produce several machine instructions. The compiler may also combine it with other code during optimization, or optimize it away entirely.
04What can change the order of execution?
if / else
Choose a path based on a condition.
Loops
Repeat a section of code.
Function calls
Temporarily run another function.
break / continue
Change the normal flow of a loop.
05Why does order matter?
int a = 3;
int b = a + 2;
The second line uses the value of a produced by the first. If the data is not ready, the program may not get the correct result.
Program flow is the study of where execution goes next, and why it goes there.
06How can you trace a program by hand?
a: not created yet
a = 3
a = 3, b = 5
This is called a program trace: recording changes to variables and output in the order they actually occur.
What you have learned
- A program has a defined control flow.
- Unless another control structure changes it, statements usually continue in order.
- An “execution pointer” is a learning model, not a real hardware arrow.
- One line of C++ does not necessarily correspond to one machine instruction.
- When reading a program, track variables, conditions, and output together.
Next: if: Teaching a Program to Make Choices
Your turn
If the program prints score first and then adds 2 to it, will the number already on the screen change by itself?
Have an answer? Click to see the explanation
Usually not. That output has already happened. To display the new score, the program needs to print it again.