Lecture 6
Lecture 6
End Process
Real-World Usage
● Initialization Routines: Often, system or application initialization routines use
sequences to prepare all components or services in a specific order.
● Data Processing Pipelines: Simple data pipelines often follow a sequence where data
is fetched, processed, and output.
● User Input Handling: A basic form is found in applications that ask users to provide
input and respond accordingly in a predetermined sequence.
❏ The sequence construct is fundamental and forms the backbone of more complex
control structures like selection (conditional) and iteration (looping) constructs.
Control Flow Constructs
● In software construction, control flow constructs are essential to determine the behavior of a program.
● Three fundamental constructs often used in algorithms and program designs are the if construct, the selection
construct, and the repetition construct. Each of these constructs alters the flow of a program based on
conditions or loops.
1. If Construct
The if construct is used to control the flow of a program based on a condition. It allows a program to execute
certain code only if a specified condition is true.
Characteristics:
● Condition-based Execution: The program checks a condition (true/false) and executes a block of code
only if the condition evaluates to true.
● Optional Else: Often used with an else statement to execute alternative code if the condition is false.
if age >= 18:
else:
The selection construct (also known as a decision construct) enables a program to choose between different
options or branches based on a condition. The most common forms of selection constructs are if-else and
switch/case statements.
3. Repetition Construct
The repetition construct (also known as a looping construct) allows a section of code to be repeated multiple
times based on a condition or counter. This construct is essential for processes that need iteration, such as iterating
over arrays or continuously checking a condition.