PF Lecture 5
PF Lecture 5
Lecture 5
Control Structures-Unit 2
Control Structures
Selection: if and if...else
Although there are only two logical values, true and
false,
they turn out to be extremely useful because they
permit programs to incorporate decision making that
alters the processing flow.
The remainder of this Lecture discusses ways to
incorporate decisions
There are two selections, or branch control structures:
if statements and the
switch structure.
This section discusses how if and if. . .else
statements can be used to create one-way selection,
two-way selection, and multiple selections.
One-Way Selection
A bank would like to send a
notice to a customer if her or
his checking account balance
falls below the required
minimum balance. That is, if
the account balance is below
the required minimum balance,
it should send a notice to the
customer; otherwise, it should
do nothing.
In C++, one-way selections
are incorporated using the if
statement. The syntax of one-
way selection is:
One-Way Selection
Note that the element of this
selecation
It begins with the reserved