In the mid-1960’s, mathematicians proved that any program, no matter how complicated, can be written using only 3 basic control structures.
Control structures are used to control which instruction will be executed next.
So far we have only used the sequence structure. The sequence control
structure is the default or overriding structure.
The sequence structure indicates instructions are to be executed one statement
at a time in the order they occur from top to bottom unless a different control
structure dictates otherwise.
The Selection Structure provides flexibility to our programs. We can do
different things depending on the situation.
We use the word IF followed by a condition to represent the Selection Structure in Pseudo-code. Actions we want to perform when the condition is True are listed following the IF. The conditional statements are usually indented for clarity. We indicate the end of the conditional statements with the words EndIf.
If Age > 65 Then
‘conditional statement
Calculate
purchaseAmount = PurchaseAmount – (PurchaseAmount * .1)
End If
Calculate Tax = PurchaseAmount * .075 ‘unconditional statement
Another Example
If HoursWorked > 40 Then
‘Conditional statement
Calculate
GrossPay = (HoursWorked – 40) * (PayRate * 1.5) + (40 * PayRate)
End IF
IF HoursWorked <= 40 Then
‘Conditional statement
Calculate
GrossPay = HoursWorked * PayRate
End IF
Calculate StateTax = GrossPay * .03 ‘unconditional
statement