Structured Programming  «Prev  Next»
Lesson 1

Introduction to Structured Programming

This module examines the fundamental concepts of structured programming. After completing the module you will have the skills and knowledge necessary to:
  1. Describe structured programming
  2. Identify disadvantages of unstructured programs
  3. Describe and use pseudocode
  4. Describe the three control flow constructs of structured programming
  5. Identify advantages of using subprograms
To begin this module, we will define what structured programming is.

Programming Methodology

Structured programming is a programming methodology aimed at improving the quality and development time of a computer program by making extensive use of functions, block structures and repetitive loops. This is in contrast to using simple tests and jumps such as the goto statement which could lead to spaghetti code which is difficult both to follow and to maintain. It emerged in the 1960s particularly from a famous letter with regards to the "Go To" Statement Considered Harmful, from Edsger Dijkstra in 1968. This was supported theoretically by the structured program theorem, and practically by the emergence of languages such as ALGOL with suitably rich control structures

Fundamental Concepts of Structured Programming

Structured programming is a paradigm aimed at improving the clarity, quality, and development time of a computer program by making extensive use of subroutines, block structures, for and while loops, and if/then/else decision-making structures. The fundamental concepts of structured programming, pivotal for producing robust software, are outlined below:
  1. Sequential Execution: This is the most basic structure where statements are executed sequentially in the order they appear. It establishes a clear and straightforward flow of control through the program, enhancing readability and predictability.
  2. Control Structures: At the heart of structured programming are the control structures that dictate the execution flow of the program. These include:
    • Selection: If/then/else structures allow the program to branch based on conditions, enabling decision-making processes within the software.
    • Iteration: For and while loops facilitate the repeated execution of a block of statements, allowing efficient processing of repetitive tasks and data structures.
  3. Modularity/Subroutines: Structured programming emphasizes dividing a program into smaller, manageable, and reusable units called subroutines or functions. Each subroutine performs a specific task and can be developed, tested, and debugged independently, contributing to the robustness and maintainability of the software.
  4. Local Variables and Limited Scope: The use of local variables within subroutines or blocks, with scopes limited to those blocks, enhances modularity and prevents side effects, making the software more predictable and reliable.
  5. Structured Looping and Branching: The avoidance of "goto" statements, which can lead to "spaghetti code," is a key principle. Structured programming advocates for well-defined loops and branching structures that make the flow of control straightforward and understandable.
  6. Top-down Design and Stepwise Refinement: This approach involves starting with a high-level overview of the system and progressively breaking it down into more detailed components. This methodical decomposition allows for a more organized development process and ensures that each component is robust and well-defined.
  7. Clear and Understandable Code: Clarity is crucial in structured programming. Code should be written in a way that is easy for others to understand, with appropriate use of comments, meaningful variable names, and a consistent coding style.
  8. Error Handling and Recovery: Robust software must be able to handle unexpected situations and errors gracefully. Structured programming encourages the explicit handling of such cases, ensuring that the program can recover from errors without compromising its integrity or losing data.

By adhering to these principles, structured programming enables the development of software that is not only robust and reliable but also easier to understand, maintain, and extend. This approach reduces complexity, minimizes the risk of errors, and facilitates collaboration among developers, contributing to the overall quality and success of software projects.

Structured programming is a subset of procedural programming that enforces a logical structure on the program being written to make it more efficient and easier to understand and modify. Certain languages such as Ada, Pascal, and Fortran 90 are designed with features that encourage or enforce a logical program structure. Structured programming frequently employs a top-down design model, in which developers map out the overall program structure into separate subsections. A defined function is coded in a separate module or subroutine, allowing the code to be loaded into memory more efficiently. After a module has been tested individually, it is then integrated with other modules into the overall program flow.
Program flow follows a simple hierarchical model that employs looping constructs such as for
  1. repeat,
  2. while and
  3. use of the Go To statement
is prohibited.
Structured programming allows any computer program to be written with just three structures:
  1. decisions,
  2. sequences, and
  3. loops.
Edsger Dijkstra's article, Go To Statement Considered Harmful was significant in the trend towards structured programming. In the methodology employed by Dijkstra, the developer separates programs into subsections that each have only one point of access and one point of exit.

SEMrush Software