Selection and Repetition Control Structures

Selection and Repetition Control Structures

Selection Control Structures

When a programmer is writing a program that needs to choose between two or more actions dependent upon whether the condition is true or false, a selection control structure is used. Relational operators such as less than (<), greater than (>) and equal to (< >, =) are used to express the conditions. The addition of selection control structures to a program gives a program more structure and the programmer has more flexibility in program construction.
There are four kinds of selection control structures:
  1. Simple selection
  2. Simple selection with null force branch
  3. Combined selection
  4. Nested selection
Suppose a programmer wants to process the results of a survey on how many people in San Diego, CA own dogs, how many own cats, how many own other types of pets and how many have no pets at all. The programmer would most likely use a nested control selection which is used when the word IF occurs more than once in an IF statement. When either the true or the false branch of one IF has another IF statement imbedded within it, it is called a nested selection. The important keywords that used in this type of selection are IF, THEN, ELSEIF, and ENDIF. The following example will illustrate the use of the nested selection:

IF No = “N”
THEN
Increase No Pet-Count by one
IF Yes = “Y”
IF Pet = “D” THEN
Increase Dog-Count by one
    ELSE
    IF Pet = “C” THEN
    Increase Cat-Count by one
          ELSE
          IF Pet = “E” THEN
Increase Exotic-Count by one
ENDIF
ENDIF
ENDIF
ENDIF

Repetition Control Structures

Repetition control structures are blocks of one or more statements that continually repeat until a specific condition is satisfied. They are also known as iteration control structures.
There are three repetition control structures and where the decision to repeat a statement is placed determines which one of the control...