Professional Documents
Culture Documents
Seventh Edition
Chapter 3
Understanding Structure
Objectives
In this chapter, you will learn about:
2
Three Basic Control Structures
Sequence, Selection, Repetition/Iteration/Looping
Connector
Use where
flowlines
come
together in
a flowchart
3
RAPTOR Flowchart Symbols
Sequence
Control
Structures
Selection and
Repetition
Control
Structures
4
Understanding the Three Basic Control Structures (continued)
expression
usually referred to as the
condition
null case
No structure
to be executed
6
Understanding the Three Basic Control Structures (continued)
• Single-alternative if
– Else clause is not required
– If the condition does not evaluate to true, the structure(s) are
not executed and control passes to the next structure
• null case
– Situation where nothing is done
– This would be the "empty" else branch of a selection structure
no yes
structure structure
8
Understanding the Three Basic Control Structures (continued)
• Dual-alternative if
– Contains two alternatives Pseudocode
keywords:
– If-then-else structure
if, then, else,
if someCondition [is true] then endif
statement_1
else structures
statement_2
endif
9
Understanding the Three Basic Control Structures (continued)
10
Understanding the Three Basic Structures (continued)
• Loop structure
– Repeats a set of actions based on the answer to a question
• Loop body
– Also called repetition or iteration
– Question is asked first in the most common form of a loop
11
Understanding the Three Basic Control Structures (continued)
Entry Point
Connector
When using
drawing software
such as Visio
13
Understanding the Three Basic Control Structures (continued)
• All logic problems can be solved using only these three control structures
• Structures can be combined in an infinite number of ways
• Stacking
– Attaching structures end-to-end at their entry/exit points
• Nesting
– discussed a few slides later…
• End-structure statements
– Indicate the end of a structure
– endif ends an if-then-else structure
– endwhile ends a pre-test loop structure
– enddo ends a post-test loop structure
14
Understanding the Three Basic Control Structures (continued)
Figure 3-6 Structured flowchart and pseudocode with three stacked structures
15
Understanding the Three Basic Control Structures (continued)
block or compound
statement
17
Understanding the Three Basic Control Structures (continued)
entry point
and
exit point
for a structure
structures
have ONE of
each
18
Understanding the Three Basic Structures (continued)
selection
Note:
The diamond
flowchart symbol
loop
is used for both
selection and
loop structures.
How do you
know if you are
looking at a
selection or loop A selection structure
structure? only has flowlines
merging at the exit point
for the structure
20
Using a Priming Input
21
Using a Priming Input (continued)
RAPTOR would
let you do this
because there
are languages
that support a
“mid-test”
condition.
Figure 3-16
23
A priming input is
OUTSIDE the loop
structure.
It precedes the
structure.
24
Figure 3-18 Structured but incorrect solution to the number-doubling problem
26
Flowchart Status
• Flowcharts fall into one of the 2 following categories:
1. structured
2. unstructured
27
Recognizing Structure (continued)
This is a no
no!
Understandable
but not
Structured
Are they:
stacked?
nested?
Are they:
structured?
• Priming input
– Statement that reads the first input data record
31