Programming Control Structures

 

You can write any program by using a combination of three control structures:

 

            (1)        sequence

            (2)        selection

            (3)        repetition (a.k.a. iteration or looping)

 

These three structures are the building blocks of all programs; they form the foundation of structured programming.

 

 

THE SEQUENCE CONTROL STRUCTURE

 

The sequence control structure is the simplest of the three structures; it is a program segment where statements are executed in sequence, one after the other:

 

 

A coding segment that would be represented by the sequence structure is one in which there is no decision-making, looping, or branching – it would simply be a series of statements, one after the other, such as the following set of statements to calculate net pay:

 

      GrossPay = HoursWorked * HourlyRate

      Ded401K = GrossPay * 0.055

      Medicare = GrossPay * 0.0145

      SocSec = GrossPay * 0.0765

      TotDeductions = Ded401K + Medicare + SocSec

      NetPay = GrossPay - TotDeductions