Structured and Unstructured Programming, CSE 101 – Study Notes
offline

Difficulty: Beginner to Intermediate | Prerequisites: Computer Programming and Language Categories notes


Big Picture

Once you know what programming languages are, the next question is how you organise the code you write. Structured programming is the dominant paradigm for writing clear, maintainable programs. It replaced the older unstructured approach, which relied on jumps and "go to" statements that produced tangled, hard-to-debug code (often called "spaghetti code"). This topic sits between the general language-categories overview and the deeper dive into data structures. It also lays the groundwork for understanding object-oriented programming later in the course.


TL;DR

Structured programming organises code using control structures (sequence, selection, iteration, recursion), subroutines, and blocks, each with a single entry and exit point. Unstructured programming runs statements sequentially with jumps and "go to" commands, producing code that is harder to read, debug, and maintain. Structured code is modular, reusable, and easier to work on as a team.


Key Terms

Structured programming

A programming paradigm that makes extensive use of subroutines, control structures, and blocks to organise a program, using a hierarchy of modules each with one entry and one exit point. Think of it as building with clearly labelled Lego blocks: each block does one thing and snaps in at exactly one place.

Unstructured programming

A programming paradigm where statements execute in the order they are written, with control transferred via "go to" and "return" statements that allow multiple entry and exit points. In simple terms, it is code that jumps around freely, making it hard to trace what runs when.

Sequence

A control structure where statements execute one after another in the order they appear.

Selection

A control structure that decides which statement or block to execute based on the outcome of a tested condition (e.g. if, else, switch). Think of it as a fork in the road: the program checks a signpost and picks a direction.

Iteration (repetition)

A control structure that executes a statement or block repeatedly until a set limit or condition is reached (e.g. for, while loops).

Recursion

A technique where a function calls itself repeatedly until a termination condition (base case) is met. In simple terms, the function solves a smaller version of the same problem each time it calls itself.

Subroutine (subprogram)

A callable program unit that performs a given task. The two main forms are functions (which return a value) and procedures (which perform an action without returning a value).

Block

A grouping of statements within a program, typically delimited by braces { } or indentation, treated as a single unit.

Spaghetti code

A pejorative term for code with complex, tangled control flow, usually caused by excessive use of "go to" statements. Difficult to read, debug, and maintain.

Top-down approach

A design strategy where the entire system is subdivided into progressively smaller compositional subsystems or modules.

Modular programming

Another name for structured programming's practice of dividing a program into self-contained, reusable modules.

Abstraction (in structured programming)

The principle that the programmer focuses on the problem being solved rather than the machine's specifications. This improves coding speed and program portability.


Core Content

Elements of Structured Programming

Structured programming rests on three pillars:

  • Control structures – sequence, selection, iteration, and recursion. Each has one entry point and one exit point, which keeps the flow predictable.

  • Subroutines / subprograms – callable units (functions and procedures) that encapsulate a specific task. They promote reuse and make testing easier.

  • Blocks – groupings of statements treated as a single unit. In C-family languages, blocks are enclosed in { }.

Key Facts About Structured Programming

  • Follows a top-down approach: the whole system is broken into subsystems, then into modules, then into individual functions.

  • Also known as modular programming.

  • A subset of procedural programming and a historical precursor to object-oriented programming.

  • Enforces abstraction: the programmer thinks about what the program should do, not how the hardware works.

  • Avoids "go to" statements and the spaghetti code they produce.

  • Found in third-generation (high-level) programming languages.

Examples of Structured Programming Languages

C, Pascal, Ada, Fortran, COBOL, ALGOL.

Advantages of Structured Programming

  • Modules can be reused within the program.

  • Multiple programmers can work simultaneously, each handling a different module.

  • Debugging is easier because each module can be tested in isolation.

  • Program testing is more thorough.

  • Development time is reduced.

Disadvantages of Structured Programming

  • Less secure than OOP because there is no built-in data hiding (encapsulation).

  • Less flexible than OOP for modelling complex, real-world relationships.

  • Less abstraction than OOP provides through inheritance and polymorphism.

Unstructured Programming: Features

  • Statements are ordered sequentially.

  • Control flow relies on basic jumps, branches, and "go to" commands.

  • Lines are usually numbered.

  • Subroutines may have several entry and several exit points.

  • Only basic data types are supported.

Structured vs. Unstructured: Comparison

  • Control flow: Structured uses control structures with one entry and one exit. Unstructured uses "go to" and return with multiple exit points.

  • Readability: Structured code is easy to follow. Unstructured produces spaghetti code.

  • Debugging: Structured programs are easier to debug. Unstructured programs are harder.

  • Code reuse: Structured supports reuse through modules. Unstructured does not.

  • Team work: Structured programs can be split across programmers by module. Unstructured programs cannot easily share tasks.


Real-World Applications

Virtually all professional software today is written using structured (or object-oriented) principles. When you open a C codebase for an embedded system, a Fortran simulation for weather modelling, or a Pascal teaching project, you are looking at structured programming in action. The modularity principle also carries into how large engineering teams divide work: each developer owns a module, tests it independently, and integrates it into the whole.


Common Misconceptions

  • Students sometimes think structured programming and object-oriented programming are the same thing. Structured programming is a precursor to OOP, but it lacks features like encapsulation, inheritance, and polymorphism.

  • "No go to" is often stated as a rule of structured programming. The principle is more nuanced: the goal is single-entry, single-exit control flow. A "go to" that breaks this principle is what structured programming avoids, but some languages still include it for edge cases.

  • Students may assume recursion is not part of structured programming because it feels less "sequential." Recursion is a recognised control structure within the structured paradigm, alongside sequence, selection, and iteration.


Why It Matters / Exam Flags

⚠️ You will almost certainly be asked to list the four control structures of structured programming: sequence, selection, iteration, recursion.

⚠️ The comparison table between structured and unstructured programming is a favourite exam topic. Know at least four differences.

⚠️ Be ready to name examples of structured programming languages (C, Pascal, Ada, Fortran, COBOL, ALGOL).

⚠️ Understand why structured programming is considered a subset of procedural programming and a precursor to OOP.

⚠️ The disadvantages (no data hiding, less flexibility and abstraction compared to OOP) appear frequently as short-answer questions.


Quick Self-Test

  1. True or False: Structured programming allows multiple exit points in a control structure.

  1. Fill in the blank: The two types of subroutines are _______ and _______.

  1. True or False: Spaghetti code is associated with structured programming.

  1. Fill in the blank: Structured programming follows a _______ approach, breaking the system into subsystems.

  1. True or False: ALGOL is an example of a structured programming language.

Answers: 1. False (single entry, single exit). 2. Functions and procedures. 3. False (it is associated with unstructured programming). 4. Top-down. 5. True.


Practice Q&A

Q: Define structured programming.

A: Structured programming is a paradigm that organises code using subroutines, control structures (sequence, selection, iteration, recursion), and blocks, each with a single entry and exit point, arranged in a hierarchy of modules.

Q: Name the four control structures used in structured programming.

A: Sequence, selection, iteration (repetition), and recursion.

Q: What is spaghetti code, and which paradigm produces it?

A: Spaghetti code is tangled, hard-to-follow code produced by excessive use of "go to" statements and jumps. It is associated with unstructured programming.

Q: Give three advantages of structured programming over unstructured programming.

A: Code reuse through modules, easier debugging (each module can be tested independently), and the ability for multiple programmers to work on separate modules simultaneously.

Q: What are two disadvantages of structured programming compared to OOP?

A: Structured programming offers less security because it lacks data hiding (encapsulation), and it is less flexible for modelling complex relationships because it does not support inheritance or polymorphism.

Q: Explain the difference between a function and a procedure.

A: A function is a subroutine that performs a task and returns a value. A procedure is a subroutine that performs a task without returning a value.


Connections to Other Topics

The control structures covered here (sequence, selection, iteration) reappear when you study algorithms and flowcharting. Recursion is central to topics like tree traversal and sorting algorithms in the data structures unit. The limitations of structured programming (no data hiding, limited abstraction) motivate the move to object-oriented programming, which you will encounter later in the course.


Related Terms / Search Tags

structured programming definition, unstructured programming, control structures, sequence selection iteration recursion, subroutines, functions vs procedures, modular programming, top-down design, spaghetti code, structured vs unstructured, CSE 101, Texas A&M, Pascal, C programming, ALGOL, COBOL, procedural programming, OOP precursor