Nassi-Schneiderman
Flowcharts
The
Decision Structure
The
decision structure is used when your program must make a choice of some
sort. In this case, it allows your
program to only execute sections of your algorithm if certain conditions are
met.
There
are two versions of the decision structure:
the single alternative and double alternative. The single alternative structure is used
when there is only one conclusion to be made by the decision. Instead of an either-or situation, it
describe a simple condition that can be stated in general terms by thinking
something like: “if condition X,
then do Y”. For example, you might
think “if it rains, then I use an umbrella.”
The
NS form of the single alternative is created with the following general diagram:

In
this case, you state the condition in the form of a true/false question (here,
what happens if the question is false is simply not considered). Note that if the condition is true, then
there is a list of one or more instructions that must be followed below the True
triangle. The False triangle is
empty, meaning that nothing is done (in terms of flow, you would simply exit at
the bottom below the False triangle).
Example
1:
Think
of the English statement “If today is Friday, then I will water the
plants”. Notice that you really don’t
need to include “else, I won’t water the plants”, because that is the same as
saying “else, do nothing” in this situation.
It simply doesn’t need to be said.
This means that we have a single-alternative If-Then statement. The corresponding NS chart would look like
this:

Example
2:
The
second example combines a chart from the discussion on the sequence structure
with a decision. Here, we read in the
price and tax rate, compute the (overall) sale price, and print it out only if
it is less than fifty dollars.
