Understanding and using sequence
Introduction
When you look at any high-level language, you can identify the features in the language that make it so powerful. Instructions in a program flow one after another in a sequence. However, there are instructions available that will allow blocks of code to be repeated many times. There are also instructions that allow decisions to be made about which code from a selection of code will be executed. The specific instructions provided by a particular language that allow code to be repeated, or code to be selected from a choice of code, are known as control structures. If we also include the way that instructions flow one after the other, we can say that there are three types of programming construct we need to know about. These are:
-
- Sequence.
- Selection. (There are two types of selection we need to know about.)
- Iteration, also called 'repetition'. (There are three types of iteration we need to know about.)
We can summarise these three constructs with a diagram:
Sequence
There isn't a lot to say about the programming construction 'sequence'. It simply describes one instruction following on from the next instruction. An example of this, in pseudo-code is:
INITIALISE Variables
WRITE ‘Please enter the name of student’
INPUT Name
WRITE ‘Please enter the exam mark of student’
INPUT ExamMark
PRINT Name, ExamMark