blog / guides

what does a computer program do? A practical beginner guide

by Luke published 8 min read

the short answer

A computer program is a list of instructions that a computer follows one at a time, exactly as written. Almost every program does four jobs: it takes something in, remembers it, works something out, and gives something back.

A computer program is a list of instructions that a computer follows, one at a time, exactly as written. That is the whole idea. Everything else, from a calculator app to a video game, is a longer and cleverer list.

This guide shows what those instructions actually do, with small programs you can run in your browser. It ends with a short exercise so you can check you have got it.

The four jobs every program does

Look closely at almost any program and you will find the same four jobs:

  1. Take something in. A tap, a key press, a file, a reading from a sensor. This is called input.
  2. Remember it. The program keeps values in the computer’s memory so it can use them later. These named values are called variables.
  3. Work something out. Adding up, comparing, deciding what to do next, or repeating a step many times.
  4. Give something back. Words on a screen, a sound, a saved file, a light turning green. This is called output.

Some programs do these in a split second. Some, like the program running your phone, keep doing them over and over until you switch it off.

A program you can run

Here is a tiny program that does all four jobs. It adds up three days of steps and says whether you hit a goal. Press run.

try it · python
steps = [4200, 6100, 5300]
total = 0
for day in steps:
    total = total + day
if total >= 15000:
    print("Total:", total, "steps. Goal reached!")
else:
    print("Total:", total, "steps. Keep going.")

You will see:

Total: 15600 steps. Goal reached!

Here is each job in that program:

  • Take something in: the three numbers on the first line. In a real fitness app they would come from your phone’s sensors.
  • Remember it: steps and total are variables. They hold values while the program runs.
  • Work something out: the for line repeats the adding once for each day. The if line decides which message to show.
  • Give something back: print shows the result.

Change 15000 to 20000 and run it again. The program makes a different decision because one instruction changed.

Programs do exactly what you write

This is the single most important thing to understand about programs. They do what you wrote, not what you meant. Run this one:

try it · python
print("2" + "2")
print(2 + 2)

You will see:

22
4

The first line has quotes, so Python treats each 2 as text and joins the two pieces together. The second line has plain numbers, so Python adds them. A person would know you probably meant 4 both times. A program cannot know that. It follows the exact instruction you gave it.

That is also what a bug is: an instruction that says something different from what you meant. Finding bugs is mostly a matter of reading your instructions the way the computer does, word by word.

What happens when you run a program

When you press run, three things happen.

  1. The code is translated. Computers do not understand Python or JavaScript directly. Another program, called an interpreter or a compiler, turns your code into instructions the computer’s processor can follow.
  2. The processor follows the instructions, in order. It starts at the top and works down, unless an instruction tells it to jump, repeat or skip. Modern processors manage billions of simple steps every second.
  3. Memory holds the values while it runs. When the program ends, those values are gone, unless the program saved them to a file or sent them somewhere.

That last point surprises many beginners. If your program counts to 100 and then stops, the count does not survive. To keep anything, a program has to save it on purpose.

Four everyday programs, broken down

Once you know the four jobs, you can spot them in anything.

A calculator app

  • In: the buttons you press.
  • Remembers: the numbers so far and the sum you picked.
  • Works out: the answer.
  • Out: the number on the screen.

A sat nav

  • In: where you want to go, and your position from GPS.
  • Remembers: a map of roads and your route so far.
  • Works out: the quickest route, and again whenever you miss a turn.
  • Out: directions on the screen and a voice telling you to turn left.

A spell checker

  • In: the words you type.
  • Remembers: a long list of correctly spelt words.
  • Works out: whether each word you typed is on the list.
  • Out: a red line under the ones that are not.

A game

  • In: your controller, keyboard or touches.
  • Remembers: your score, your lives and where everything is.
  • Works out: what moved, what crashed into what, and whether you won.
  • Out: a new picture on screen, many times a second.

A game runs those four jobs in a loop that never stops until you quit. Many programs work this way.

Where programs live

Programs are everywhere, not just on computers.

  • Your phone and laptop: every app, and the operating system that runs them.
  • Websites: a program on a server builds each page, and JavaScript in your browser makes it react to you.
  • Household things: washing machines, microwaves, smart speakers and car dashboards all run programs.
  • Things you never see: traffic lights, card machines and lifts.

The programs inside household things are often small and do one job. The ideas are exactly the same.

What a program cannot do

  • Guess what you meant. If an instruction is wrong, it follows the wrong instruction.
  • Fix its own mistakes. It can only check for problems you told it to check for.
  • Understand meaning. To a program, a name is just a run of letters. It does not know who Sam is.
  • Remember after it stops, unless it saved what it needed.

None of that is a weakness, really. It is what makes programs reliable. The same instructions give the same result every time.

Common misunderstandings

  • “You have to be good at maths.” Most programs add, count and compare. You learn the maths a program needs as you go.
  • “Programs are written in ones and zeros.” The processor works with them in the end, but people write programs in languages made of words, like print and if.
  • “You need to memorise everything.” Programmers look things up all the time. What you learn is how the instructions fit together.
  • “A program is one big file.” Many are built from lots of small pieces, each doing one job.

A short exercise

Pick an alarm clock app on a phone. On paper, write down its four jobs: what it takes in, what it remembers, what it works out, and what it gives back.

Then change the step counter above so it checks four days instead of three, with a goal of 20,000 steps. Run it to check your answer.

One possible answer

The alarm clock takes in the time you set and the current time. It remembers your alarm time. It works out whether the current time matches. It gives back a sound.

For the step counter, add a fourth number to the list, like [4200, 6100, 5300, 4800], and change 15000 to 20000. The total is 20400, so it prints that you reached the goal.

Your next step

You now know what a program does. The quickest way to make it stick is to write one. Gwecode’s Start Here course covers these ideas in 13 short lessons, about an hour and a half in all, and ends with your first real code. Every lesson is free and runs in your browser, so there is nothing to install. Create a free account to keep your progress, or start the first lesson now.

practise this · lessonWelcome: What Is a Program?start the lesson

questions

What is the difference between a program and an app?

An app is a program, or a group of programs, packaged for people to use, with the buttons, pictures and files it needs. Every app is built from programs, but plenty of programs are not apps: many run quietly in the background.

What is the difference between code and a program?

Code is the written instructions. A program is those instructions put to work by a computer. People often use the two words for the same thing.

Do programs think?

No. A program follows its instructions one step at a time, exactly as written. Even AI tools run as programs, though their behaviour is shaped by huge amounts of data rather than written out line by line.

What language are programs written in?

Hundreds of them. Python, JavaScript, Java and C# are some of the most common. They look different, but they all describe the same kinds of instructions.

How do I write my first program?

Start with one line that shows a message. In Python it is print("Hello"). Gwecode’s first Python lesson walks you through it in about five minutes.

keep going.