Internet of everything
Internet of everything

This free course is available to start right now. Review the full course description and key learning outcomes and create an account and enrol if you want a free statement of participation.

Free course

Internet of everything

3.3.2 Define basic programming

Described image
Figure _unit3.3.1 Figure 19

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.

IOE_1

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, find out more about the types of qualifications we offer, including our entry level Access courses and Certificates.

Not ready for University study then browse over 900 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 prospectus