21.08.2013 Views

Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

88 Chapter 7 ■ Structured programming<br />

Figure 7.1 The three structures of structured programming<br />

One view of structured programming is that it holds that programs should only be<br />

built from three components: sequences (normally written in the order in which the<br />

statements are to be executed), selections (normally written as if-then-else), and<br />

repetitions (written as while-do). The goto statement is, by implication, banned. In<br />

this chapter we begin by examining the controversy about the goto statement. The<br />

outcome of the argument is that gotos are an irrelevancy; the argument is about something<br />

else, good program structure. We go on to explore the significant principles of<br />

structured programming.<br />

There are some other principles. We will explore these using flowcharts, which<br />

describe flow of control. A flowchart is read from the top downwards or in the direction<br />

of the arrows. Flowchart decisions (corresponding to if or while statements in<br />

code) are drawn as diamonds. Flowchart activities are shown as rectangular boxes. A<br />

flowchart is very similar to a UML activity diagram and conveys the same in<strong>for</strong>mation.<br />

If the three structures of structured programming are diagrammed as flowcharts<br />

(Figure 7.1), the following characteristics become clear:<br />

1. they have only one entry and exit<br />

2. none of the constructs consists of more than three boxes<br />

Figure 7.2 A control structure that is not structured

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!