Structured programming emphasizes programming language constructs such as <bold>while</bold> loops, <bold>until</bold> loops, and <bold>if then else</bold> statements. Properly used, these constructs make occurrences of loops and branching of control obvious. They are preferable to <bold>goto</bold> statements, which tend to obscure the flow of control [DDH,DIJ]. This paper describes an algorithm which transforms a flowgraph into a program written using <bold>repeat</bold> (<bold>do forever</bold>) and <bold>if then else</bold> statements. The goal of the algorithm is to produce readable programs, rather than to avoid the use of <bold>goto</bold> statements entirely. <bold>goto</bold> statements are generated when there is no better way to describe the flow of control.
A number of techniques for eliminating <bold>goto</bold> statements from programs have been previously published [AM, BJ, BS, COO, KF, KOS, PKT]. However, these techniques do not necessarily produce clear flow of control [KN]. Misuse of control constructs may mislead the reader into expecting patterns of control flow which do not exist in the algorithm. For example, these techniques may use a <bold>repeat</bold> statement when the contained code cannot be executed more than once or add numerous control variables to avoid <bold>goto</bold> statements. They also may avoid <bold>goto</bold> statements by copying segments of code or creating subroutines. The former method results in longer programs and bugs may be introduced when all the identical segments must be modified. The latter method may result in subroutines which appear unnatural.
[1]
Brian W. Kernighan,et al.
RATFOR—a preprocessor for a rational fortran
,
1975,
Softw. Pract. Exp..
[2]
David C. Cooper,et al.
Böhm and Jacopini's reduction of flow charts
,
1967,
CACM.
[3]
S. Rao Kosaraju.
Analysis of Structured Programs
,
1974,
J. Comput. Syst. Sci..
[4]
Alfred V. Aho,et al.
The Theory of Parsing, Translation, and Compiling
,
1972
.
[5]
Kenneth Steiglitz,et al.
The Expression of Algorithms by Charts
,
1972,
JACM.
[6]
Jeffrey D. Ullman,et al.
Flow graph reducibility
,
1972,
SIAM J. Comput..
[7]
Tadao Kasami,et al.
On the capabilities of while, repeat, and exit statements
,
1973,
Commun. ACM.
[8]
Jeffrey D. Ullman,et al.
Characterizations of Reducible Flow Graphs
,
1974,
JACM.
[9]
Edsger W. Dijkstra,et al.
Letters to the editor: go to statement considered harmful
,
1968,
CACM.
[10]
Robert W. Floyd,et al.
Notes on Avoiding "go to" Statements
,
1971,
Information Processing Letters.
[11]
Donald E. Knuth,et al.
Structured Programming with go to Statements
,
1974,
CSUR.
[12]
Zohar Manna,et al.
Translating Program Schemas to While-Schemas
,
1975,
SIAM J. Comput..
[13]
Edsger W. Dijkstra,et al.
Structured programming
,
1972,
A.P.I.C. Studies in data processing.
[14]
Corrado Böhm,et al.
Flow diagrams, turing machines and languages with only two formation rules
,
1966,
CACM.