Structured programming notes

2. Control Structures

2.3. Iteration Control Structure

The Iteration Control Structure, also known as a looping structure, allows a program to repeat a set of instructions multiple times as long as a specified condition is satisfied. It is used when the same task needs to be performed repeatedly, which helps reduce code duplication and makes programs more efficient.

In structured programming, iteration plays a key role in tasks such as counting, searching, data processing, and generating repeated output.

How Iteration Works

  1. A condition is evaluated.

  2. If the condition is true, the loop body is executed.

  3. After execution, the condition is checked again.

  4. The loop continues until the condition becomes false.

Types of Iteration Control Structures with Examples

1. while Loop (Entry-Controlled Loop)

The condition is checked before executing the loop body. If the condition is false initially, the loop may not execute at all.

Example: Print numbers from 1 to 5.

 
int i = 1; while (i <= 5) { printf("%d ", i); i++; }

2. do–while Loop (Exit-Controlled Loop)

The loop body is executed at least once, because the condition is checked after the execution.

Example: Print numbers from 1 to 5.

 
int i = 1; do { printf("%d ", i); i++; } while (i <= 5);

3. for Loop

The for loop is used when the number of iterations is known. Initialization, condition, and update are written in a single line.

Example: Print numbers from 1 to 5.

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

Key Features of Iteration Control Structures

  • Automates repetitive tasks

  • Makes programs concise and readable

  • Supports nested loops for complex logic

  • Reduces errors caused by repeated code

Summary

The Iteration Control Structure enables a program to repeat a block of code efficiently until a condition is met. By using loops like while, do–while, and for, programmers can handle repetitive tasks effectively in structured programming.