16 Programming and Data Structures
Fig. 1.20 Sequence algorithm
The above is a sequence algorithm and all the above six instructions are followed by the system. In
case some problem occurs, for example, after step 1, after dialing if the line is busy, there is no
alternative operation defined in the sequence to either exit or redial. In such a case, remaining
instructions will not be followed. This problem can be overcome by using selection method.
2) Selection: We understood that the algorithms written in sequence fashion are not reliable. There
must be a procedure to handle operation failure occurring during execution. The selection statements
can be as shown in Fig. 1.21.
If (condition)
Statement 1;
Else
Statement 2;
Fig. 1.21 Selection statements
In case the operation is unsuccessful, the sequence of algorithm should be changed/corrected in
such a way that the system will re-execute until the operation is successful. The above sequence of
algorithm can be modified as follows so that the system responds.
1) Dial the phone number
If (busy tone)
Goto step 1
2) Phone rings at the called party
3) Caller waits for the response
4) Called party picks up the phone