1. Introduction to structured programming

Structured programming is a way of writing programs that emphasizes clarity, logic, and maintainability. Instead of jumping around unpredictably in code, programs are built using a small set of well-defined control structures.

The main idea:
A program should be easy to read, understand, test, and modify.

Why Structured Programming Exists

Early programs relied heavily on  statements, which caused “spaghetti code” to follow, error-prone, and painful to debug.

Structured programming was introduced to:

  • Improve program reliability

  • Make code easier to understand

  • Reduce logical errors

  • Support team development

Core Principles

Structured programming is based on three fundamental control structures:

1. Sequence

Statements are executed one after another, in order.

Read input Process data Display output

2. Selection (Decision Making)

The program chooses between alternatives.

Examples:

  • if

  • if–else

  • switch

  • if (score >= 50) { printf("Pass"); } else { printf("Fail"); }

3. Iteration (Repetition / Looping)

A block of code runs multiple times.

Examples:

  • for

  • while

  • do–while

  • for (int i = 1; i <= 5; i++) { printf("%d\n", i);