Sequence is the order in which programming statements are executed. Programming statements usually run one after another in order, unless one of the other programming constructs is used. The sequence of a program is extremely important as once these are translated, carrying out instructions in the wrong order leads to a program performing incorrectly.
In this pseudo-code program, designed to find the average of two whole numbers, the instructions are in in the wrong sequence:
total ← 0 average ← number1/number2 OUTPUT “Enter the first number” number1 ← USERINPUT OUTPUT “Enter the second number” number2 ← USERINPUT OUTPUT "The average is " + average
Running this program would result in a logic 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:
total ← 0 OUTPUT “Enter the first number” number1 ← USERINPUT OUTPUT “Enter the second number” number2 ← USERINPUT average ← number1/number2 OUTPUT "The average is " + average
Having statements in the wrong order is one of the simplest, yet most common, logical programming errors. The error occurs no matter which programming language is used.