
Dec 3 Q5: Control Structures
December 2, 2007
- What is the purpose of a control structure?
The Purpose of a control structure is to when a program does not follow the linear sequence of instructions, and it does things like repeat codes and take decisions, a control structure is what is used to specify the instructions that will be carried ot during that proccess.
For each of the following, describe what exactly happens and give an example from real life.
- Sequencing control structure
Sequence control refers to the user actions and computer logic which initiate, interrupt, or terminate transactions. Sequence control governs the transition from one transaction to the next. One example of this in real life is a lollipop man on a busy road who is able to stop the traffic flow, slow down the trraffic flow and allow cars to go through.
2. Selection control structure
In Selection structures, you are able to make one or two-way decisions with an “ if ” statement, and you can move through multiple possible paths by using a switch statement. Your decisions are either based on the relationship between values, with the relational operators, or you can make decisions based on the value of a simple data variable. One example of this in real life are cars on a road. If i car reaches two roads, one which is bunmpy , the other which is smooth, depending on the car’s situation, If it is good condition it will go on the rough road, if it is not, it will go on smooth.
3.Repetition control structure
In Repetition control structures, the path of the program repeats and repeats until a certain condition is met, for instance, at lunch bernard ate corn. Bernard would keep biting,chewing and then swallowing until the condition of “no corn left” is met.