Three Basic Structures Of Structured Programming

Length: 1073 words (3.1 double-spaced pages)
Rating: Excellent
Open Document
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Text Preview

More ↓

Continue reading...

Open Document

Structured programming is one of the several different ways in which a programming language can be constructed. "It was originally introduced as a means of getting away from the 'spaghetti' code that was used in the early days and to provide some means by which programmers could more easily follow code written by other programmers." (Hendren, 1998) Structured programming is a procedure-oriented method of designing and coding a program.
At a low level, structured programs are composed of simple, hierarchical program flow structures. "These are regarded as single statements, and are the same time ways of combining simpler statements, which may be one of these structures, or primitive statements such as assignments or procedure calls." (Dijkstra, 1990) The three basic types of structure identified by Dijkstra were concatenation, selection, and repetition.

Simple sequential code is most easily expressed by concatenation i.e. listing the pieces of code in the correct order. The main related question is how to indicate the boundary between statements. "Some languages just use the end of line but then usually require an explicit continuation symbol for statements too long to fit on a single line. Others languages use an explicit character such as, with some of these treating it as a separator and the rest treating it as the statement terminator." (Birrell, 1995)
To turn a code sequence into a single entity, usually known as a compound statement, some languages use an explicit pair of brackets, such as {} or begin end, as a general form useable with any structure. Some languages have specific forms for each structure, such as if fi (or if end if) and while od (or while end while). Some languages have both general and specific forms, and others have neither. Because structures often end up deeply nested, specific keywords can be much easier to pair up than general pairs.
"The classic selector is the conditional or if statement/expression, and almost all languages have it, usually in two slightly different forms such as if then and if then else." (Agresti, 2000) Some languages place restrictions on the then and else parts, but most modern languages have no such restrictions, allowing nested if statements.
One common pattern of use is:
If ... then...
Else if ... then...
Else if .

How to Cite this Page

MLA Citation:
"Three Basic Structures Of Structured Programming." 24 Mar 2017

Related Searches

.. then...
. . .
else ...
And this has given rise to a different kind of selection construct, the case or switch. This first arose as a modified goto:
goto label_array[n]
But this was even more dangerous than normal gotos, and was also replaced. A switch construct is essentially a list of (value, action) pairs. We can generalize the switch into a block of guarded statements, where at most one of the statements is obeyed e.g.:
I < j then j -= I
j < I then I -= j
We can even allow for more than one of the guard expressions being valid, either by picking the first such in the list, or by non-deterministically picking a valid guard at random.
"Repetition comes in two forms: recursion and loops. Some languages have both; some only have one or the other. Loops come in two forms: indeterminate, where the number of repetitions is unknown until the loop terminates, and determinate, where the number of repetitions is known when the loop starts. Again, some languages with iteration have both forms, some only one and the other." (Jackson, 2002)
Dijkstra's (indeterminate) repetition construct, which involves a test in the middle of the loop, is not often directly implemented in programming languages. However, special cases of it are common: a version with the first box missing so the test is at the start is found in most languages, and a version with the last box missing so the test is at the end is often found as well.
"Almost all languages provide some sort of determinate loop, usually known as a for-loop or do-loop. The basic form is a loop that e.g. counts from 1 to 10, and some languages provide little more than this: e.g.: for I = 1 to 10 do." (Fream, 1992)
Because of this some languages do not bother to test the condition until the end of each repetition. Various enhancements exist: variables or expressions for start and stop values, increments other than 1, decrements, automatic declaration of the counter variable, scalar types other than integer.
Some languages guarantee a particular value of the counter outside the loop or permit it to be modified inside the loop, whereas others do not, so as to allow for optimizations and because modifying the counter does not lead to good quality code.
We can transform the while statement into a loop containing a list of guarded statements, that repeats until none of the guards is valid e.g.:
I < j do j -= I
J < I do I -= j
This example terminates when I equals j.

Coders should break larger pieces of code into shorter subroutines (functions, procedures. methods, blocks, or otherwise) that are small enough to be understood easily. In general, programs should use global variables sparingly; instead, subroutines should use local variables and take arguments by either value or reference. These techniques help to make isolated small pieces of code easier to understand without having to understand the whole program at once.

Erosa, Hendren: (1998) Structured Programming, Language Design, and Persistence.

E.W. Dijkstra: (1990) Structured Programming: Three Basic Structures of Structured Programming, Academic Press, London.

Andrew D. Birrell: (1995) Programming with Threads, Research Report 35, Systems Research Center, Digital Equipment Corporation.

William Agresti: (2000) Three Basic Structures of Structured Programming, Journal of Programming.

M.A. Jackson: (2002) Basic controls and structures of Structured Programming, Journal of software development.

Skinner Fream: (1992) Structured Programming, program flow structures, Yale University press

Return to