Thursday, September 2, 2010

Structured Programming

Structured programming states that any program can be created through the use of three procedures: sequence, selection, and repetition.

1. Sequence: One thing happens, then another, then another... Get bowl, Place bowl, fill bowl with 1 cup cereal, put 1/4 cup milk in bowl, scoop cereal, eat cereal. To make this work each process must be done in order, else you may be eating your cereal off of the table.

2. Selection: Selection is the decision portion of your program. If you don't have a bowl in front of you, then grab a bowl. If you have a bowl to put on the table, then put it on the table. If there is no cereal in your bowl, then put cereal in the bowl... by now I'm sure you get the gist.

3. Repetition: Repetition tells the program to do something again and again as needed (or specified by you, the programmer). At the end you can add a selection, if hungry repeat. You already have a bowl, so the program continues to the next step. The bowl is filled (because you have only taken one bite), you continue until you are either no longer hungry or the bowl is empty, in which case the bowl would refill and you would eat until no longer hungry.

Anything else you want to do can be done by placing one or more of these within themselves (i.e. nesting statements) but every programming element is a composition of one or more of these three.

The examples given are not necessarily complete, there are practically an infinite number of steps that could be inserted (breathing between bites, wait time between bites, chewing, swallowing, etc. etc. etc.), but you should have a general understanding of structured programming.

2 comments:

  1. your background hurts my eyes :(

    ReplyDelete
  2. Thank you for your input. I decided that was a bit much and toned it down a little.

    ReplyDelete