Nassi-Schneiderman
Flowcharts
The
Double Alternative Decision Structure
The
double alternative decision structure is used when your program must make a
choice in which there are two possible outcomes to a decision. It is used when you have an either-or
situation (in other words, a decision in which the two possible outcomes are
mutually exclusive). In general terms,
think of it as saying something like “if condition X, then do Y, otherwise
do Z”. For example, “If I like
the Ford, then I buy the ford, otherwise I buy the Chevrolet.”
The
NS form of the double alternative is created with the following general
diagram:

As
with the single alternative structure, you state the condition in the form of a
true/false question. What happens if
the question is false is considered here. Whether the condition is true or false, there is a
list of one or more instructions that must be followed below the corresponding
triangle.
Example
1:
Think
of the English statement “If my friend comes over, then we’ll play Nintendo,
else I study for CS 105.” Notice that
both of these are mutually exclusive in the sense that you can’t (I think)
study for CS 105 and play Nintendo simultaneously. This means that we have a double-alternative If-Then-Else
statement. The corresponding NS chart
would look like this:

Example
2:
The
second example combines a chart from the discussion on printing the maximum of
two numbers. Here, we read in the two
numbers (called n1 and n2) and print out the one that has maximum value. Keep in mind that this implicitly calls n2
the maximum if they are actually equal.
