Structured Programming  «Prev  Next»

Structured Programming Terms

  1. Unstructured programming: Tends to produce programs that are difficult to understand and expensive to maintain
  2. Structured programming: A form of programming that breaks complex tasks into smaller, simpler tasks
  3. Pseudocode: Outlines the logic of a program in structured English
  4. Subprogram: A program within a program
  5. Sequence: Performing tasks in a particular order
  6. Decision: Conditionally performing a task
  7. Repetition: Repeatedly performing a task

Structured programming is a programming paradigm aimed on improving the clarity, quality, and development time of a computer program by making extensive use of subroutines, block structures and repetition constructs. This is in contrast to using simple tests and jumps such as the goto statement which could lead to "spaghetti code" which is both difficult to follow and to maintain as was shown by Edsger Dijkstra .


Control Structures and Structured Program Theorem:

Following the structured program theorem, programs are seen as composed of control structures:
  1. Sequence: ordered statements or subroutines executed in sequence.
  2. Selection: one or a number of statements is executed depending on the state of the program. This is usually expressed with keywords such as if-then-else.
  3. Iteration: a statement or block is executed until the program reaches a certain state, or operations have been applied to every element of a collection. This is usually expressed with keywords such as while, repeat, for or do..until. Often it is recommended that each loop should only have one entry point and only one exit point.
  4. Recursion: A statement is executed by repeatedly calling itself until termination conditions are met. While similar in practice to iterative loops, recursive loops may not be more computationally efficient because the parameters rest on the local call stack.

Struktogram showing directional flow within a program
Struktogram showing directional flow within a program

Struktogram showing conditional statement to determine which branch will be executed
Struktogram showing conditional statement to determine which branch will be executed