2. Control Structures

2.2. Selection Control Structure

The Selection Control Structure is a programming construct that allows a program to make decisions and choose one path of execution from multiple alternatives based on a given condition. Instead of executing all statements sequentially, the program evaluates a condition and executes only the block of code that satisfies that condition.

This control structure is essential in structured programming because it enables programs to respond differently to different inputs or situations.

How It Works

  • A condition or logical expression is evaluated.

  • If the condition is true, a specific block of statements is executed.

  • If the condition is false, an alternative block may be executed or the program skips that section.

Common Selection Statements

  • if statement – executes a block when a condition is true

  • if–else statement – chooses between two alternatives

  • nested if statement – checks multiple conditions

  • switch / case statement – selects one option from many based on a value

Key Characteristics

  • Enables decision-making in programs

  • Improves flexibility and logic control

  • Avoids unnecessary execution of statements

  • Makes programs dynamic and interactive

Importance

Selection control structures help programs handle real-world decision scenarios, such as grading systems, menu-driven programs, and validation checks.