Lesson 2: Multiple Selection Constructs

What is a Multiple Selection Construct?

A multiple selection construct is a type of control structure that allows a program to choose between two or more alternative paths based on a condition — like a traffic light, where the action taken depends on the colour shown.

Types of Multiple Selection Constructs

  • If-Else statements: like being at a coffee shop — if you want tea, you take one path; if you want coffee, you take another.
  • Switch statements: like a phone menu, where the number you press leads to a different option.
  • Nested if statements: like being at a restaurant — if you want breakfast, you have another choice to make (e.g., eggs or pancakes).

Worked Examples

Using If-Else to determine shipping cost:

If weight <= 1kg
  Cost = 500frs
Else
  If weight <= 5kg
    Cost = 1000frs
  Else
    Cost = 2000frs

Using a Switch statement to determine the day of the week:

Switch (number)
  Case 1: Day = "Monday"; Break
  Case 2: Day = "Tuesday"; Break
  Case 3: Day = "Wednesday"; Break
  ...

Using Nested If statements to determine ticket type:

If age <= 18
  If destination = "Local"
    Ticket = "Child Local"
  Else
    Ticket = "Child International"
Else
  If age >= 60
    Ticket = "Senior"
  Else
    Ticket = "Adult"

Leave a comment

Your email address will not be published. Required fields are marked *

sponsors Ads