It is feasible to perform structured programming in any kind of programming language, though it is preferable to usage something like a procedural programming language. Several of the languages initially used because that structured programming include: ALGOL, Pascal, PL/I and also Ada—but most new procedural programming languages since that time have consisted of features to encourage structured programming, and sometimes intentionally left out features—notably GOTO—in an initiative to do unstructured programming more difficult. Structured programming (sometimes well-known as modular programming) is a subset the procedural programming the enforces a logical structure on the regimen being composed to make it more efficient and easier to understand and also modify.

You are watching: A structured program must contain a sequence, selection, and loop structure.


Theoretical foundation

The structured regimen theorem gives the theoretical communication of structured programming. It states that three means of combine programs—sequencing, selection, and also iteration—are adequate to express any kind of computable function. This monitoring did not originate with the structured programming movement; these frameworks are enough to explain the instruction bike of a central processing unit, and the procedure of a Turing machine. Therefore a processor is constantly executing a “structured program” in this sense, also if the instructions the reads indigenous memory space not component of a structured program. However, authors commonly credit the result to a 1966 document by Böhm and also Jacopini, possibly since Dijkstra cited this file himself. The structured routine theorem walk not deal with how come write and also analyze a usefully structured program. These concerns were addressed during the late 1960s and also early 1970s, with significant contributions through Dijkstra, Robert W. Floyd, Tony Hoare, Ole-Johan Dahl, and David Gries.


P. J. Plauger, very early adopter of structured programming, described his reaction to the structured routine theorem:

Us converts waved this interesting bit of news under the noses the the unreconstructed assembly-language programmers who retained trotting soon twisty bits that logic and saying, ‘I betcha can’t structure this.’ neither the evidence by Böhm and also Jacopini nor our repetitive successes at creating structured code carried them roughly one work sooner than they were ready to to convince themselves.

Donald Knuth welcomed the principle that programs must be written with provability in mind, but he do not agree (and tho disagrees) through abolishing the GOTO statement. In his 1974 paper, “Structured Programming with Goto Statements”, he gave examples where he thought that a direct jump leader to fingerprint and much more efficient password without sacrificing provability. Knuth propose a looser structural constraint: It have to be possible to draw a program’s flow chart through all front branches top top the left, all backward branches top top the right, and no branches crossing every other. Plenty of of those knowledgeable in compilers and also graph theory have supported allowing just reducible flow graphs.

Structured programming theorists obtained a major ally in the 1970s ~ IBM researcher Harlan Mills used his translate of structured programming theory to the development of one indexing system for the brand-new York Times study file. The task was a good engineering success, and also managers at other companies cited it in assistance of adopting structured programming, although Dijkstra criticized the methods that Mills’s translate differed indigenous the released work.

As late together 1987 it to be still feasible to progressive the inquiry of structured programming in a computer system science journal. Dijkstra did therefore in the year with a letter, “GOTO taken into consideration harmful.” plenty of objections followed, consisting of a response from open minded Rubin that sharply criticize both Dijkstra and the concessions other writers made once responding come him.


By the end of the 20th century almost all computer system scientists were encouraged that that is valuable to learn and also apply the principles of structured programming. High-level programming languages that initially lacked programming structures, such as FORTRAN, COBOL, and also BASIC, now have actually them.

Common deviations

While goto has now mainly been replaced by the structured constructs of an option (if/then/else) and repetition (while and for), few languages room purely structured. The most common deviation, uncovered in many languages, is the use of a return statement for at an early stage exit indigenous a subroutine. This results in multiple leave points, rather of the single exit point required through structured programming. There are various other constructions to handle cases that are awkward in completely structured programming.

Early exit

The most common deviation indigenous structured programming is beforehand exit native a duty or loop. At the level the functions, this is a return statement. At the level the loops, this is a rest statement (terminate the loop) or proceed statement (terminate the present iteration, proceed with next iteration). In structured programming, these have the right to be replicated by including additional branches or test, yet for returns from nested password this can add significant complexity. C is very early and prominent example of these constructs. Some newer languages also have “labeled breaks”, which enable breaking the end of an ext than simply the innermost loop. Exceptions also enable early exit, but have more consequences, and thus are treated below.

Multiple exits deserve to arise because that a variety of reasons, most regularly either that the subroutine has no an ext work to carry out (if returning a value, it has completed the calculation), or has encountered “exceptional” circumstances that protect against it from continuing, thus needing exception handling.

The most typical problem in beforehand exit is that cleanup or final statements room not enforcement – for example, allocated memory is not unallocated, or open papers are not closed, leading to memory leaks or source leaks. These should be excellent at every return site, which is brittle and also can easily result in bugs. For instance, in later on development, a return statement can be overlooked through a developer, and also an activity which have to be performed in ~ the finish of a subroutine (e.g., a map statement) can not be performed in every cases. Languages there is no a return statement, such as standard Pascal don’t have this problem.

Most contemporary languages carry out language-level assistance to avoid such leaks; see thorough discussion at resource management. Most typically this is done via unwind protection, which ensures that details code is guaranteed to be run when execution exit a block; this is a structured alternate to having a cleanup block and also a goto. This is most regularly known as try...finally, and considered a part of exception handling. Various approaches exist come encapsulate source management. An alternate approach, uncovered primarily in C++, isResource acquisition Is Initialization, which provides normal stack unwinding (variable deallocation) at role exit to contact destructors on regional variables come deallocate resources.

Kent Beck, boy name Fowler and co-authors have suggested in your refactoring books that nested conditionals might be harder to recognize than a certain form of flatter structure using multiple exits predicated by security clauses. Your 2009 book flatly states that “one exit allude is really no a valuable rule. Clarity is the crucial principle: If the an approach is clearer through one leave point, use one leave point; otherwise don’t”. They sell a cookbook solution for transforming a function consisting only of nested conditionals into a succession of guarded return (or throw) statements, adhered to by a solitary unguarded block, i beg your pardon is intended to contain the password for the typical case, if the guarded explanation are claimed to address the less common ones (or with errors). Herb Sutter and Andrei Alexandrescu also argue in your 2004 C++ tips book that the single-exit suggest is an useless requirement.

In his 2004 textbook, David Watt writes the “single-entry multi-exit regulate flows are regularly desirable”. Using Tennent’s framework notion of sequencer, Watt uniformly describes the control flow constructs uncovered in modern-day programming languages and also attempts to explain why certain varieties of sequencers space preferable to rather in the context of multi-exit control flows. Watt writes the unrestricted gotos (jump sequencers) are a poor because the location of the jump is not self-explanatory to the leader of a regime until the reader finds and also examines the actual label or address that is the target the the jump. In contrast, Watt says that the conceptual intent that a return sequencer is clean from its own context, without having actually to study its destination. Watt writes the a course of sequencers well-known as escape sequencers, characterized as “sequencer that terminates execution that a textually enclosing command or procedure”, incorporates both division from loops (including multi-level breaks) and also return statements. Watt likewise notes that while run sequencers (gotos) have been somewhat minimal in languages favor C, whereby the target have to be an inside the local block or one encompassing external block, that restriction alone is not adequate to make the intent of gotos in C self-describing and so they can still develop “spaghetti code”. Watt additionally examines how exemption sequencers different from escape and jump sequencers; this is explained in the following section of this article.

See more: Clue: Religion Founded In 19Th Century Persia, Religion Founded In 19Th

In comparison to the above, Bertrand Meyer composed in his 2009 textbook that instructions choose break and also continue “are just the old goto in sheep’s clothing” and strongly advised against their use.

Exception handling

Based ~ above the coding error native the Ariane 501 disaster, software developer Jim Bonang says that any exceptions thrown indigenous a duty violate the single-exit paradigm, and propose the all inter-procedural exceptions should be forbidden. In C++ syntax, this is excellent by proclaiming all role signatures as throw() Bonang proposes the all single-exit conforming C++ should be composed along the currently of: