Skip to content

A Program Is Instructions

Trace a one-instruction program, distinguish output from an action, and compare a result with what you intended.

  • Foundations

This course teaches the ideas behind every programming language, rather than one language. You do not need a computer to follow it.

We write each idea in pseudocode: plain words for a person to read, not a machine to run. Every real language spells these ideas its own way. The ideas underneath stay the same, and those are the ones worth keeping.

A program is a list of instructions

A program gives instructions. In our first examples, execution starts at the top and follows each line in turn. Later we will choose between instructions and repeat them. For now, follow one short sequence.

Here is a one-instruction program, which shows a word.

Code
SHOW "Hello"

Trace it and the output is:

Output
Hello

That is a whole program. You asked for a word, and you got a word. Nothing else happened, because you asked for nothing else.

Every language has its own way of showing something. BASIC says PRINT. Python says print. C calls printf. We say SHOW. A machine lesson explains how its own output reaches the screen. The purpose here is to show a word.

The computer does what you say

A valid instruction can do the wrong job. If we meant to show "Hello" but wrote "Goodbye", the program can display Goodbye without a complaint. It cannot infer the greeting we intended. Other mistakes, such as an unfinished quotation, may stop a real language from accepting the program.

Start by comparing what happened with what you expected. Check the instructions and how you ran them. Tools and hardware can fail too; an unexpected result is a reason to investigate, not proof that the learner is at fault.

If SHOW "Put your shoes on" runs, has the computer put anyone’s shoes on?

Show the explanation

No. SHOW displays the words. It does not carry out the action those words describe. Output is something we can read and check.

When it’s wrong, see why

  • The computer refuses the line. Check the quotation marks. SHOW "Hello has one at the start and none at the end, so the computer cannot tell where the words stop.
  • Nothing happens. You wrote the program but never ran it. A program waits until you tell it to go.
  • You get a message you do not understand. Read it anyway. It usually names the problem and the line it happened on, which is more help than it looks.

What you’ve learnt

  • Our first programs are sequences followed from top to bottom.
  • A valid instruction can express the wrong intention; other errors may be diagnosed.
  • Output is how a program shows you something: SHOW here, PRINT in BASIC, and its own way in every language.

What’s next

One instruction is a program. So is a hundred. In Unit 2 we give the computer more than one thing to do, and find that the order matters as much as the instructions do.

You can try this idea by entering real instructions on a Spectrum in Meet BASIC. The lesson explains the Spectrum’s own syntax as you use it.