2. Recognizing Structures
When you are beginning to learn about
structured program design, it is difficult to
detect whether a flowchart of a program’s logic
is structured.
In recognizing structure, the three basic
structures must be taken into consideration.
By recognizing its structure we can identify if
there are tangled or unstructured flowchart
segments.
3. Example 1:
Does the flowchart
segment
structured?
How many
structures does
the flowchart
segment have?
What structures do
you recognize
from the flowchart
segment?
Sequence
Selection
Figure 1
4. Example 2:
Does the flowchart
segment
structured?
How many
structures does
the flowchart
segment have?
What structures do
you recognize
from the flowchart
segment?
Loop
Selection
Figure 2
5. Example 3:
Does the
flowchart
segment
structured?
No, it is not built
from the three
basic structures.
Figure 3
This part of
the segment
is not
structured
6. Spaghetti Bowl Method
One way to straighten out an unstructured
flowchart segment is to use the “spaghetti
bowl” method.
That is, picture the flowchart as a bowl of
spaghetti that you must untangle. Imagine you
can grab one piece of pasta at the top of the
bowl and start pulling. As you “pull” each
symbol out of the tangled mess, you can
untangle the separate paths until the entire
segment is structured.
7. Spaghetti Bowl Method (cont’d.)
Use the Spaghetti Bowl Method to structure
the flowchart segment
Start pulling at Figure 3 top
Encounter procedure box Labeled A (Figure 3-1)
Figure 3-1 Untangling Example 3, first step
8. Spaghetti Bowl Method (cont’d.)
Next item is a question
Testing condition labeled B (Figure 3-2)
Now know sequence starting with A ended
Figure 3-2 Untangling Example 3, second step
9. Spaghetti Bowl Method (cont’d.)
Pull flowline from “No” side of Question B
Encounter C (Figure 3-3)
Figure 3-3 Untangling Example 3, third step
10. Spaghetti Bowl Method (cont’d.)
Pull flowline from “Yes” side of Question B
Encounter D (Figure 3-4)
Figure 3-4 Untangling Example 3, fourth step
11. Spaghetti Bowl Method (cont’d.)
Follow line on left side of Question D
If line attached somewhere, untangle by repeating
tangled step
Continue pulling flowline emerging from Step
C
Reach end of program segment (Figure 3-5)
Figure 3-5 Untangling Example 3, fifth step
12. Spaghetti Bowl Method (cont’d.)
Pull right side of Question D
Process E pops up (Figure 2-6)
Reached the end
Figure 2-6 Untangling Example 3, sixth step
13. Spaghetti Bowl Method (cont’d.)
Question D brought together: selection
structure
Question B loose ends brought together:
selection structure
Figure 3 Finished flowchart and
pseudo code for untangling
Example 3
14. Describing Three Special
Structures –
Case, While and Do-Until
Three more forms of basic structures
Case
Alternative decision-making structure
Do-while
Alternative to while loop
Do-until loops
Alternative to while loop
Sometimes convenient
All acceptable, legal structures
15. The Case Structure
Several possible values exists for single
variable being tested
Each value requires different course of action
Flow passes through only one alternative
Flowchart, pseudo code, program code
convenience
Easier to understand at first glance
Examples
Figure 4-1: series of decisions
Figure 4-2: case structure implementing decisions
16. The Case Structure (cont’d.)
Figure 4-1 Flowchart and pseudo code of tuition
decisions
17. The Case Structure (cont’d.)
Figure 4-2 Flowchart
and pseudo code of
case structure
18. The While Loop
while loop
Condition tested at structure beginning
Condition not met at first test
Code in while structure body never executed
Also called a pretest loop
Figure 4-3 The while loop
19. The Do-While or Do-Until Loops
do-while loop
Condition tested at structure end
Body has executed at least once
Expressed as a sequence followed by a loop
Also called a posttest loop
Figure 4-4 The do-while or do-until loop
Notes de l'éditeur
Yes it is structured..
2 structures
Sequence and Selection
NOTE: notice that the segment has only one entry point and exit point.
Yes it is structured..
2 structures
Loop and a Selection within the Loop
NOTE: notice that the segment has only one entry point and exit point.