Lesson 1: Sequence and Selection Control Structures

Sequence Control Structures

A sequence control structure is a type of control structure that executes a series of statements in a specific order, one after the other — like following a recipe step by step. For example, making tea: boil water, add tea leaves, stir, pour into cup. Changing the order of the statements would result in a different outcome (e.g., adding tea leaves before boiling water).

Selection Control Structures

A selection control structure is a type of control structure that allows a program to choose between two or more alternative paths based on a condition — like being at a crossroads and deciding which path to take.

Example: determining the cost of shipping an item:

  1. If weight ≤ 1kg, then cost = 500frs
  2. Else, if weight ≤ 5kg, then cost = 1000frs
  3. Else, cost = 2000frs

Example: determining the area of a rectangle using selection:

  1. Input length and width
  2. If length == width, then Area = length x width (square)
  3. Else, Area = length x width (rectangle)
  4. Output Area

Leave a comment

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

sponsors Ads