The function of structural components of programs - EdexcelSequence

Programs are designed and implemented using common building blocks, known as programming constructs. These constructs are sequence, selection and iteration and they form the basis for all programs.

Part ofComputer ScienceApplication of computational thinking

Sequence

is the first programming construct. In programming, are one after another. Sequence is the order in which the instructions are executed.

The sequence of instructions is extremely important as carrying out instructions in the wrong order results in a program performing incorrectly.

An explanation of sequencing, as used in algorithms and programming

In this , designed to find the average of two whole numbers, the instructions are in in the wrong sequence:

SET total TO 0 SET average TO number1/number2 SEND ‘Enter the first number: ‘ TO DISPLAY RECEIVE number1 FROM (INTEGER) KEYBOARD SEND ‘Enter the second number: ‘ TO DISPLAY RECEIVE number2 FROM (INTEGER) KEYBOARD SEND ‘The average is ‘ & average TO DISPLAY

Running this program would result in an error because it tries to calculate the average before it knows the values of the numbers.

This version has the instructions in the correct sequence:

SET total TO 0 SEND ‘Enter the first number: ‘ TO DISPLAY RECEIVE number1 FROM (INTEGER) KEYBOARD SEND ‘Enter the second number: ‘ TO DISPLAY RECEIVE number2 FROM (INTEGER) KEYBOARD SET average TO number1/number2 SEND ‘The average is ‘ & average TO DISPLAY

Writing instructions in the wrong order is one of the most common programming errors. It happens no matter which is used.