Total Pageviews

Tuesday, May 10, 2011

Control Structures

In the world of programming, programmers incorporate control structures to create efficient and user-friendly programs. Similar to steps in a set of instructions with one or more possible outcomes, control structures are blocks of programming that evaluate variables and decide which direction to proceed based on a set of parameters. The four basic control structures in programming are sequence, selection, loop, and unconditional branch. Some of the common terms that can be found in control structures are if, then, else, while, and goto. Terms like these are utilized to set the direction of the program and determine its calculated outcome.
 
The simplest form of these programming control structures would be the Sequence control structure. In this form of control structure, the computer carries out the program statements in a designated sequence, one after the other. In addition, this type of structure is also considered the simplest type of programming structure because it can hold the more complex structures together. A simpler method to understand this form of programming structure is to imagine an employee who is required to carry out a set of procedures, in a designated order, in order to fulfill a daily task at their place of work.


Next, let us focus on the Selection control structure. This form of control structure is utilized to create the alternative to pursue a certain path or a different path. This structure is often programmed utilizing code such as an IF statement, or a CASE statement. An easier way to better understand this form of programming structure is to imagine an employee who is getting ready for work and has a decision to make. This employee gets their briefcase, gets their bag, and if it is raining, the person will get their coat. In both cases, programming and the example above, if the last statement is not true, then the process stops at the prior statement.

Now, let us focus on the Iteration control structure. This form of control structure, also known as loop control structure, is programming structure that is utilized to reiterate a process or processes in the program syntax. This structure is often programmed utilizing terms like loop, while, when, and for. Another way to look at this control structure is to imagine an employee whose job it is to fill a bucket with a gallon of water using a cup to transfer the water from a sink. The employee would have to repeat the process of filling the cup with water and transferring the water to the bucket until the bucket had a gallon of water in it.

Finally, let us focus on the Unconditional Branch control structure. This form of control structure, also known as goto control structure, is to provide a way for the execution of the program to jump to a labeled location in the program syntax. This structure is often programmed utilizing terms like goto, break, and exit. Another way to look at this control structure is to imagine an employee who works at the register, and receives a large a $100 bill as payment for $20 of rendered services and must provide change. Does the employee have enough change? If the employee does, they will provide the customer change. If the employee does not, the employee will get extra change, and then provide the customer with change.

1 comment: