The Structure Theorem
According to the Structure Theorem, a whole computer program can be divided into small pieces of codes that are used to perform a particular task. These smaller tasks can be merged in such a way that these tasks can perform any larger task without making any errors.
The structure theorem forms the basic framework for structured programming. It states that it is possible to write any computer program by using only three basic control structures such as:
1.Sequence
The sequence control structure is the straightforward execution of one processing step after another. In an algorithm, we represent this construct as a sequence of pseudocode statements: Statement a Statement b Statement c Each of these instructions is executed in the order in which it appears. These instructions are usually one of the first four basic operations: to receive information, put out information, perform arithmetic, and assign values.
2.Selection
The selection control structure is the representation of a condition and the choice between two actions. The choice depending on whether the condition is true or false. This construct represents the decision-making abilities of the computer and represents the fifth operation, namely to compare two variables and selected one of two alternate actions. In pseudocode, selection is represented by the keywords: IF, THEN, ELSE and ENDIF.
Statement(s) in true case
ELSE
Statement(s) in false case
ENDIF
If the condition is true then the statement or statements in the true case will be executed, and the statements in the false case will be skipped. Otherwise, (the ELSE statement) the statements in the true case will be skipped and the statements in the false case will be executed. In either case, control then passes to the next processing step after the delimiter ENDIF.
3.Repetition / Iteration
WHILE loop is a leading decision loop; that is the condition is tested before any statements are executed. If the condition in the WHILE loop is found to be true, the block of statements following the condition is executed once. The delimiter ENDWHILE then triggers a return of control to the retesting of the condition. If the condition is still true, the statement block is repeated, and so the repetition process continues until the condition is no longer true. It is imperative that at least one statement within the statement block can alter the condition and eventually renders it false. Otherwise, the logic may result in an endless loop.