Saturday, December 4, 2010

Project 10 – Control Structures


  1. Four basic control structures and their sub-constructs
  2. Sequence
  3. Selection (Decision, If Then/Else) - Case Statement Available in Some Language
  4. Loop (looping, iteration) - For Statement Available in Some Language
  5. Unconditional Branch (Goto)


Control Structures
Control structures are how one defines a block of programming that analyzes variables and determines the order in which instructions or statements are executed within the program. In defining these structures, one is able to better understand the construct of a program.



Sequence Structure

A Sequence Structure is a control structure in which a program carries out individual steps in the order that they are provided (perform action A, and proceed to action B, and so on, and so forth).

A Sequence Structure is identified by the lack of variables that would change or interrupt the instructions of the code. There are no choices of which the program must choose, nor are there any situations in which the program will repeat a step, or deviate from the current path to a new one, based on a set of criteria.

For this reason, Sequence Structure much simpler than the other control structures.





 
Selection Structure

Referenced as Decision Structure, this structure allows for conditions to be input into the code as variables. Based on a test of these conditions, the program can determine the next operation with which to proceed.

These tests are based on determining whether the condition is true or false, with one result pointing to one set of actions and the second option pointing to an alternate set of actions.

Instructions can be implemented in the form of an if statement, or if-else statement (along with even more complex statements that allow for a larger number of available actions.




Loop Structure

Looping statements enable the program to repeat one or more instructions. Because of this, less code may be written to accomplish repetitive tasks.

The types of looping statements are as follows:

  • WHILE WEND loop: The WHILE WEND loop prevents an endless loop by implementing a condition that the program must check to be true.
  • FOR NEXT loop: A FOR NEXT loop tells the computer to repeat a set of instructions a specific number of times.
Each time a set of instructions are repeated, it is called iteration. It is with the results of the prior iteration, that the next iteration is started. This allows the loop to build upon itself towards a goal (in which it usually finds its end).




Unconditional branch Structure

The GOTO statement performs a one-way jump to another set of instructions outside of linear code, or even another application entirely. Unlike the Conditional Branch structure--which provides the option to either take the branch path, or not, an Unconditional Branch Structure incorporates a branch of actions that must be performed, once the branch statement is reached within the code.

A proper GOTO statement branches into an executable statement, and cannot branch into IF or LOOP statements.





No comments:

Post a Comment