Control Structures
Sequence
Selection
Iteration
A structured program is defined by D'Orzio (1990) as:
A computer program which is implemented using only those
control structures which are found in structured program
designs.
What makes a program design structured? In 1964, Bohm and Jacopini published a paper
which demonstrated that any problem can be solved by using the three logic control
structures of sequence, selection and iteration (or repetition). The three structured
programming constructs are illustrated in flowchart and statement form below.
Sequence
The sequence control structure consists of processes which are carried out in a sequential
manner:
STATEMENT A
STATEMENT B
STATEMENT C
Our Do Payroll algorithm is an example of a simple sequential control structure.
Sequence Control Structure
Major Tasks: Do Payroll
DO Enter Pay Details
DO Calculate Pay
DO Print Pay Details
DO Update Employee Records
Subtask: Enter Pay Details
INPUT employee name
INPUT weekly hours
INPUT rate of pay
Subtask: Calculate Pay
CALCULATE gross = hours * rate
CALCULATE tax = gross * .23
CALCULATE net = gross - tax
Subtask: Print Pay Details
PRINT employee name
PRINT gross
PRINT tax
PRINT net
Subtask: Update Employee Record
OPEN employee record
WRITE employee pay details
UPDATE year to date figures
Selection
The selection control structure consists of a condition which is either True or False.
Processes will be carried out depending on the result of the condition test.
In pseudocode, selection is represented by the IF, THEN, ELSE, and ENDIF statements.
IF Condition is true THEN
DO Process A
ELSE
DO Process B
ENDIF
Using our Morning Routine algorithm, we can apply the selection control structure to the
Take a Shower task.
Iteration
The iteration control structure consists of actions that need to be repeated over and over again
while a particular condition is true. This is the concept of the LOOP.
In pseudocode, iteration is represented by the WHILE and ENDWHILE statements.
WHILE Condition is true DO
Process statements
ENDWHILE
We can apply the iteration control structure to the major tasks of our Do Payroll algorithm.