What is Structured Programming?

Rumman Ansari   Software Engineer   2023-02-08   338 Share
☰ Table of Contents

Table of Content:


What is Structured Programming?

Structured programming is a specific approach to programming that generally produces well-written and easily read programs. Nothing can make up for a programmer rushing to finish a program by proceeding in what he thinks is the fastest way. You often hear, “Later, I’ll make it structured, but for now, I’ll leave it as it is.” Later never comes. People use the program until one day, when changes have to be made, the changes turn out to take as long as or longer than it would take to scrap the entire program and rewrite it from scratch.

Just because a program is well written and easily read doesn’t necessarily mean it’s structured.

What are the elementary structures of structured programs?

  • Block: It is a command or a set of commands that the program executes linearly. The sequence has a single point of entry (first line) and exit (last line).
  • Selection: It is the branching of the flow of control based on the outcome of a condition. Two sequences are specified: the 'if' block when the condition is true and the 'else' block when it is false. The 'else' block is optional and can be a no-op.
  • Iteration: It is the repetition of a block as long as it meets a specific condition. The evaluation of the condition happens at the start or the end of the block. When the condition results in false, the loop terminates and moves on to the next block.
  • Nesting: The above building blocks can be nested because conditions and iterations, when encapsulated, have singular entry-exit points and behave just like any other block.
  • Subroutines: Since entire programs now have singular entry-exit points, encapsulating them into subroutines allows us to invoke blocks by one identifier.

Structured programming includes the following three constructs:

  • Sequence
  • Decision (also called selection)
  • Looping (also called repetition or iteration)

C is called a structured programming language because to solve a large problem, C programming language divides the problem into smaller modules called functions or procedures each of which handles a particular responsibility. The program which solves the entire problem is a collection of such functions.

Structured programming is a paradigm that aims to make programs easier to comprehend from a reader's point of view. It does this by linearising the flow of control through a program. In structured programming, execution follows the writing order of the code. Structured programming caught favor with programming languages for its iconic opposition to the keyword goto, aiming to reduce the prevalence of spaghetti code. Some other controversial features that most languages have not adopted are avoiding early exit and opposition to exceptions for control flow.