<< Chapter < Page | Chapter >> Page > |
Thus, the general requirement for the sequence structure is that one or more actions may be performed in sequence after entry and before exit.
There may not be any branches or loops between the entry and the exit.
All actions must be taken in sequence.
However, it is important to note that one or more of the action elements may themselves be sequence, selection, or loop structures.
If each of the structures that make up the sequence has only one entry point and one exit point, each such structure can be viewed as a single action elementin a sequence of actions.
The sequence structure is the simplest of the three, and there's not much more that I can say about it.
The selection or decision structure can be described as shown in the pseudocode in Image 2 .
Once again, there is only one entry point and one exit point.
The first thing that happens following entry is that some condition is tested for true or false .
The concept of something being true or false is commonly referred to as a boolean condition in computer programming (named after George Boole) .
If the condition is true, one or more actions are taken in sequence and control exits the structure.
If the condition is false, none , one or more different actions are taken in sequence and control exits the structure. (Note the inclusion of the word none here.)
Once again, each of the action elements in the sequence may be another sequence, selection, or loop structure.
Eventually all of the actions for a chosen branch will be completed in sequence and control will exit the structure.
It is often the case that no action is required when the test returns false. In that case, control simply exits the structure without performing any actions.
The loop or iteration structure can be described as shown in the pseudocode in Image 3 .
As before, there is only one entry point and one exit point. Note that in this case, the exit point is not at the end of the pseudocode. Instead,it follows the test.
The first thing that happens following entry is that a condition is tested for true or false.
If the test returns false, control simply exits the structure without taking any action at all.
If the test returns true:
During each iteration, if the test returns false, control exits the structure. If the test returns true, the entire process is repeated.
Each of the action elements may be implemented by another sequence, selection, or loop structure.
Notification Switch
Would you like to follow the 'Teaching beginners to code' conversation and receive update notifications?