Internet of everything
Internet of everything

Start this free course now. Just create an account and sign in. Enrol and complete the course for a free statement of participation or digital badge if available.

3.3.2 Define basic programming

What is a program?

A computer program is a set of instructions given to a computer, to be executed in a specific order. Because computers do not speak human languages, computer programming languages were created. These languages allow humans to write instructions in a way that computers can understand. While there are several different computer languages, all computer languages are based on logical structures.

The figure shows the most common logical structures found in programming languages:

  • IF condition THEN instructions (If/Then) - This is one of the most common programming structures. It is used to introduce conditional code execution. The set of instructions following the THEN keyword is only executed if the condition given is true. If the condition is false, the instructions are never executed. For example, IF password = 12345, THEN display'password correct'. The code above would only show the 'password correct' message if a password of 12345 is entered.
  • FOR expression DO instructions (For/Do) - This logical structure is used to create controlled loops. The set of instructions is executed as many times as defined inexpression. When expression is no longer met, the loop ends and the computer moves on to the next instruction. For example, FOR count<=10 DO display 'not 10 yet!'. The program will check the value of the variable called count. As long as the count is less than or equal to 10, it will display 'not 10 yet!' on the screen. As soon as the count is greater than 10, the structure is abandoned and the computer moves on to the next line of code.
  • WHILE condition DO instructions (While/Do) - The WHILE logical structure is also used to create controlled loops, but in a different way. WHILE executes instructions as long as thecondition is true. When the condition is no longer true, the structure is abandoned and the computer moves on to the next line of code. For example, WHILE temperature sensor> 80DOshow 'temperature too high!' on screenThe message 'temperature too high!' will display repeatedly until the value of the temperature sensor is less than or equal to 80.

Logical conditions like these are the building blocks of computer programs.

Take your learning further

Making the decision to study can be a big step, which is why you'll want a trusted University. The Open University has 50 years’ experience delivering flexible learning and 170,000 students are studying with us right now. Take a look at all Open University courses.

If you are new to University-level study, we offer two introductory routes to our qualifications. You could either choose to start with an Access module, or a module which allows you to count your previous learning towards an Open University qualification. Read our guide on Where to take your learning next for more information.

Not ready for formal University study? Then browse over 1000 free courses on OpenLearn and sign up to our newsletter to hear about new free courses as they are released.

Every year, thousands of students decide to study with The Open University. With over 120 qualifications, we’ve got the right course for you.

Request an Open University prospectus371