Thursday, March 3, 2011

Project 10 - Programming as Easy as DNA

Control Structures - How Programming is as Simple as Genetics


To state the obvious, everyone creates a program with a purpose. To do whatever the program needs to do, it needs to manipulate, change (fold, bend, mutilate or spindle), or alter data. There are almost as many variations as there are programs, but just like the letters used in DNA represent four simple molecules (A is for adenine, G is for guanine, C is for cytosine, T is for thymine), Control Structures, which control the flow of operations in a program, come in four basic forms: Sequence, Selection, Iteration, and Branching. These four general methods of altering data or causing a result to be calculated, displayed, or inputted into a program can be combined into remarkably complex algorithms. Whenever looking at the code of a program, key words (such as if; if else; switch; goto; continue; when; etc.) that indicate a cyclic process show where data is being manipulated.

The simplest method of furthering the goals of a program would be the Sequence, where a program is asking the computer to do one thing at a time, in sequence. This type of structure is the simplest type of programming structure that holds more complex structures together. A very simple example of this would be the display of instructions that are too long to fit on one screen. In the code of the program might be an instruction to display the first screen, then pause for a period of time, and then display the next screen. Often in a programming language, the word “next” indicates a sequence structure.



Selection is the process of branching based on inputs or decisions that are made.This is the stuff of so many science fiction movies and choose your own adventure books, where the decisions that are made determine the path the program will take. Phrasing such as If-Then-Else in a program often indicates a selection structure. In the case of If-Then-Else programs, it is giving a fork in the road for a program, as if to say “If you come to an intersection, then you should take the high road, else you should keep on taking the low road.” In other words, continue one action until a predefined circumstance happens, and then take a second action instead.



The Iteration process is one of repetition, where an action is repeated. Unless there is a logical flaw with the program, at some point a programmer should create a circumstance where the iteration comes to a stop. In the case of a fixed iteration, the process will repeat until a count has been satisfied , such as an instruction to run around the track six times. Another way of using an Iteration process would be to embed a Selection process inside an Iteration process, allowing the process to repeat infinitely until the circumstance listed in the selection process allows a new path of action. An example of this behavior might be “Check your inbox every two minutes until you get a note that your daughter in college is home safe. Only then can you finally go back to bed and sleep.” Look for keywords such as Loop, While, Exit, and When to recognized an Iteration process.



A Branching sequence is the final, comparatively little used variant. It is rarely used in object oriented languages, but often seen in languages such as Basic or C. Branching statements act like a road sign in one part of a program, directing the computer to go to a different part of the program to continue processing. In non-object oriented programming languages, look for phrases such as: break, continue and goto to identify a Branching sequence. A branching sequence is often used for common subroutines that need to be performed over and over again at different times in the programs process.



Resources:

No comments:

Post a Comment