Grade 7 Computer Science · What a program is
Order is meaning
The same instructions in a different order are an entirely different program.
The same lines, a different order, a different result
You can take three valid lines, swap two of them, and get a program that runs with no error at all — and prints something else. How do you catch a mistake like that when the computer does not even complain?
A program is not a list of things to do — it is a sequence. The computer executes a line, finishes, and moves to the next, always in that order. That sounds obvious until one sees how many mistakes come from exactly here.
x = 5
print(x)print(x)
x = 5| The order | What happens |
|---|---|
| Creation then use | Works |
| Use then creation | An error — it does not yet exist |
When order changes the result and not only validity
Sometimes both orders are valid and run without an error — and give different results. That is the more dangerous case, because there is no error message to tell you that you were wrong. If you update a value and then print it, you see the new one; if you print and then update, you see the old one. Both programs “work”, and only one does what you wanted.
score = 10
score = score + 5
print(score)Example 1 — why the first line fails
- The computer reaches the line
print(x). - It looks for a value called x.
- The line that creates it has not yet run.
- There is nothing to print, so an error.
Example 2 — why two valid orders are more dangerous
- Both versions run with no error message.
- One prints the old value and the other the new.
- Nothing warns that you chose the wrong one.
- So one must read the order, not only run it.