Structured Programming Summary
-
Java includes
only single-entry/single-exit
control statements—there is only one way to enter and only one way to exit
each control statement.
-
Connecting control statements in sequence to form structured programs is
simple. The final state of one control statement is connected to the initial
state of the next—that is, the control statements are placed one after
another in a program in sequence. We call this control-statement
stacking.
-
The rules for forming structured programs also allow for control statements to
be nested.
-
Structured programming promotes simplicity.
-
Bohm and Jacopini: Only three forms of control are needed to implement an
algorithm:
-
Sequence
-
Selection
-
Repetition
-
The sequence structure is trivial. Simply list the statements to execute in
the order in which they should execute.
-
Selection is implemented in one of three ways:
-
if
statement (single selection)
-
if…else
statement (double selection)
-
switch
statement (multiple selection)
-
The simple
if
statement is sufficient to provide any form of selection—everything that can
be done with the
if…else
statement and the
switch
statement can be implemented by combining
if
statements.
-
Repetition is implemented in one of three ways:
-
while
statement
-
do…while
statement
-
for
statement
-
The
while
statement is sufficient to provide any form of repetition. Everything that can
be done with
do…while
and
for
can be done with the
while
statement.