Structured Programming  «Prev  Next»
Lesson 5 Sequence
Objective Describe the sequence construct

Sequence of Statements

Sequence[1] is the easiest construct of structured programming to understand. It is simply the idea that a program is a sequence of statements that are executed one after the other. In more general terms, we can say that a program performs a sequence of tasks one after the other.
Donald Knuth, in his monumental work "The Art of Computer Programming (TAOCP)"", does not explicitly refer to the "Sequence Construct" using that specific terminology. However, the concept is embedded in the foundational structure of how programs are described and analyzed.
Here's the context:
  • Knuth's volumes are focused more on algorithms, data structures, and the mathematics of programming than on teaching structured programming per se.
  • He discusses control structures, flow of control, and structured programming techniques in general, especially in Volume 1 (Fundamental Algorithms), but often through assembly-level pseudocode or flowcharts rather than high-level structured programming terminology.

Sequence as a Concept in TAOCP
The idea of sequential execution is a core assumption in most of his code descriptions. In fact:
  • His MIX assembly language model naturally follows sequential instruction execution unless directed otherwise via jumps or conditional branches.
  • He assumes sequential flow in almost all the presented algorithms unless explicitly interrupted.

Summary
  • Term "Sequence Construct": Not explicitly used.
  • Concept of Sequence: Absolutely fundamental and omnipresent throughout TAOCP.

Edsger W. Dijkstra

Edsger Dijkstra, a pioneer of structured programming, emphasized the clarity and correctness of code through disciplined program structures. Within this framework, the "Sequence Statement" represents the most fundamental construct, which involves executing instructions one after another in a linear, top-down fashion. Dijkstra viewed this concept not as something to be debated or formalized extensively but as a natural and intuitive starting point for understanding program behavior. In his vision, any program's logic begins with the assumption that one instruction follows another unless deliberately altered by control structures such as selection or iteration.
Dijkstra championed structured programming to eliminate the chaos introduced by unrestrained use of **goto** statements, which often disrupted the clear, sequential flow of logic. In doing so, he promoted three essential control structures: sequence, selection (e.g., if-then-else), and iteration (e.g., while loops). The sequence, being the simplest, serves as the default behavior a kind of "zero-effort" control structure where operations are performed in the order they are written. For Dijkstra, preserving and recognizing this natural flow helped reduce program complexity, making it easier for programmers to reason about correctness and design provably correct software.
Although Dijkstra did not dwell heavily on the sequence construct itself, since it is inherently straightforward, he valued its role as the backbone of structured programming. He encouraged programmers to build logic in nested, hierarchical blocks using only these structured elements, thereby increasing code readability, maintainability, and reliability. In his seminal 1968 letter, *"Go To Statement Considered Harmful,"* he implicitly reinforced the importance of maintaining sequential flow whenever possible, using structured alternatives to maintain logical coherence. Thus, while not elaborated as a distinct theory, the sequence statement remains a silent pillar in Dijkstra's structured programming paradigm.

Sequence Example: GoForARide

For example, consider the following GoForARide program.
Put on cycling clothes
Go for a ride
Remove cycling clothes
Take a shower

For this program to work correctly, the statements must be executed in a particular sequence. More specifically, they must be executed in the order in which they appear in the program. Here is a flowchart of this program that may help you visualize the sequence in which the statements are performed.
Sequence Construct flowchart
The image consists of two parts that illustrate the "Sequence Construct" in structured programming using a simple real-world analogy, preparing for and completing a cycling activity.
Left Side (Text Instructions)
The left part of the image shows a "step-by-step list of actions":
  1. Put on cycling clothes
  2. Go for a ride
  3. Remove cycling clothes
  4. Take a shower

These steps are written in a straightforward, linear order and represent a "natural sequence" of tasks.
Right Side (Flowchart)
The right part visualizes the same steps in a flowchart format. Each step is enclosed in a rectangular box, connected by arrows pointing downward, which indicates the direction of execution. The arrows show that the steps must be completed in order, from top to bottom:
  • Start with "Put on cycling clothes"
  • Proceed to "Go for a ride"
  • Then "Remove cycling clothes"
  • Finally "Take a shower"

Analysis This image perfectly illustrates the "Sequence control structure", which is a foundational concept in structured programming where actions are executed "one after the other without branching or looping". It conveys that in both human activities and computer programs, sequence ensures "logical and orderly progression" from start to finish.

Program Sequence

An example of verbal instructions for crossing a river using a sequence statement.
  1. Take the goat across the river and return with no passengers
  2. Take the cabbage across the river and return with the goat
  3. Take the wolf across the river and return with no passengers
  4. Take the goat across the river

The sequence is one of the three basic logic structures in computer programming. The other two logic structures are selection and loop. In a sequence structure, an action or event leads to the next ordered action in a predetermined order. The sequence can contain any number of actions, but no actions can be skipped in the sequence. The program, when run, must perform each action in order with no possibility of skipping an action or branching off to another action.
  • Sequence: Finite versus Infinite Set
    The most important distinction between elementary structured types and types of advanced structure is that in the former case the cardinality of the type is strictly finite, provided that the cardinality of the constituent types is. The distinction between a 1) finite and 2) an infinite set is one of profound mathematical significance, and it has many consequences relating to methods of representation and manipulation.
    1. Since the number of potential values of the type may be infinite, the amount of storage allocated to hold a value of an advanced structure is not determinable from the declaration itself. It is normally only determined when the program is actually running, and in many cases, varies during the execution of the program. In the case of an elementary structure, the number of different potential values is finite, and the maximum amount of storage required to hold any value is fixed and determinable from the form of the declaration.
    2. When the size of a structured value is fairly large, it is more efficient to update individual components of the structure separately, rather than to assign a fresh value to the entire structure. Even for elementary types, it has been found sometimes more efficient to perform selective updating, particularly for unpacked representations of Cartesian products and for arrays. The increased efficiency of selective updating is usually even more pronounced in the case of advanced data structures.
    3. Advanced data structures, whose size varies dynamically, require some scheme of dynamic storage allocation and relinquishment. The units of storage which are required are usually linked together by pointers, sometimes known as references or addresses; and their release is accomplished either by explicitly programmed operations, or by some form of general garbage collection. The use of dynamic storage allocation and pointers leads to a significant complexity of processing, and the problems can be particularly severe when the data has to be transferred between the main and backing store of a computer. No problems of this kind need arise in the case of elementary data structures.
    4. Suitable Representation: The choice of a suitable representation for an advanced data structure is often far more difficult than for an elementary structure; the efficiency of the various primitive operations depends critically on the choice of representation, and therefore a sensible choice of representation requires a knowledge of the relative frequency with which these operations will be invoked. This knowledge is especially important when a part or all of the structure is held on a backing store; and in this case, the choice of repreisentation should take into account the characteristics of the hardware device; that is, arrangement of tracks and cylinders on a rotating medium, and times of head movement and rotational delay. In the case of elementary structures, the primitive operations are of roughly comparable efficiency for most representations.

Advanced and Elementary Structures

Thus the differences between advanced and elementary structures are quite pronounced, and the problems involved are significantly greater in the advanced case. This suggests that the practical programmer would be well advised to confine himself to the use of elementary structures wherever possible, and to resort to the use of advanced structures only when the nature of his application forces him to do so. The first and most familiar example of an advanced data structure is the sequence. This is regarded as nothing but a sequence of an arbitrary number of items of some given type. The use of the term "sequence" is intended to cover sequences on magnetic tapes, disc, or drum, or in the main store. Sequences in the main store have sometimes been known as streams, lists, strings, stacks, deques, queues, or even sets. The term file (or sequential file) is often used for sequences held on backing store. The concept of a sequence is an abstraction, and all these structures may be regarded as its various representations.
In the next lesson we will look at the decision construct.

[1]Sequence: Control flow construct in which tasks are preformed in a particular order.

SEMrush Software