Programs and data

The main purpose of computer programs is to collect and process data. A computer can change what it does depending on the data that it has to work with.

The data that is used in a program is referred to as the data values. These influence the sequence of instructions and the program outputs.

The data values collected and used by a program control:

  • what is done
  • what is stored
  • what is transmitted to other devices
  • what is output to the user (visually, audibly)

Data values can be input by a user or obtained from a range of different sources:

  • from a file, database or other piece of software
  • sent from another computer or device
  • collected from a hardware sensor such as a camera or microphone
  • generated internally, eg by the ticking of the system clock

Even mouse movements and button clicks are input data, and the location and timing of them can affect what happens.

Fixed and variable data values

Algorithms have data values that can be fixed or variable.

Question

The following algorithms each use data values. Can you work out which of these is using fixed values and which is using variable values?

Algorithm A

Add 4 to 5 Print the result

Algorithm B

Ask the user to type in a whole number Add 5 to that number Print the result

Algorithm C

If 4 is less than 5 Add 5 to 4 Print the result Otherwise Print "no"

Algorithm D

Ask the user to type in a whole number If the number typed in is less than 5 Add 5 to the number typed in Print the result Otherwise Print "no"

Algorithms A and C are using fixed values (4 and 5). There is no option within the algorithm to alter the data. These algorithms will always produce the same results.

Algorithms B and D are using variable data. The data input depends on the choice of the user. The algorithm will output a different result dependent on the user input.

curriculum-key-fact
The algorithm sets up the possibilities - it provides the set of instructions that can be executed. The data fed into a program controls the sequence of instructions and decides what gets executed.