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 orderWhat happens
Creation then useWorks
Use then creationAn 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

  1. The computer reaches the line print(x).
  2. It looks for a value called x.
  3. The line that creates it has not yet run.
  4. There is nothing to print, so an error.

Example 2 — why two valid orders are more dangerous

  1. Both versions run with no error message.
  2. One prints the old value and the other the new.
  3. Nothing warns that you chose the wrong one.
  4. So one must read the order, not only run it.
Two identical lines print two different values: order is meaning.