Control Structures
Control Structures
CSC 1106
Introduction to Programming and
Problem Solving | Fundamentals of
Computer Programming
Control Structures
BSc CS|BIT
Lecture Outline
◻ The True branch and the False branch can come from any of the
lower three points of the diamond.
◻ It is best to be as consistent as possible in choosing the points of the
diamond on which these branches are placed.
◻ The convention is to draw the True branch on the right and the False
branch on the left or bottom, although it depends on the decisions to
be made.
◻ The processing flow from both the True branch and the False branch
must connect to the rest of the processing somewhere before exiting
the program.
◻ There can be no dangling flowchart blocks—blocks with no flowlines
leading to another block, the processing must flow somewhere.
© IUIU – 2021. 9/23/24
◻ A simple decision with only one condition and one action or set
of actions (one instruction or set of instructions) for True and
another for False is relatively simple.
◻ For example, assume you are calculating pay at an hourly rate
and overtime pay (over 40 hours) at 1.5 times the hourly rate.
◻ The decision to calculate pay would be stated in the following
way:
If the hours are greater than 40, Then the pay is calculated for overtime,
or Else the pay is calculated in the usual way.
◻ There are three types of decision logic you will use to write
algorithms for solutions consisting of more than one decision.
◻ These types of decision logic include
Straight through logic,
Positive logic, and
Negative logic.
◻ When the resultant is False, that is, when the hours are not greater
than 40, the pay is processed at the normal rate.
◻ When the resultant of the first decision is False, that is, when the
PayType is not equal to “Hourly,” then the pay is processed at the
salary rate.
◻ Notice that when the PayType is not equal to “Hourly,” the
embedded decision on the True branch cannot be processed—an
example of negative logic.
◻ A good programmer thoroughly tests algorithms that use decision
logic with many sets of test data.
◻ Every path in every algorithm is checked, and a separate set of data is
used for each path.
◻ It is important to test each path so errors will be eliminated.
© IUIU – 2021. 9/23/24