BHAGWAN MAHAVIR UNIVERSITY
Bhagwan Arihant Institute & Technology
Artificial Intelligence
Ch: 5 Introduction to
Control Structures
Prolog
Name: Rutvika Ghadiyali Professor Name: Prof. Shivani Patel
[ 2307020703011 ]
Learning Objectives
Understand Control Identify Types Implementation
Structures
Differentiate between Learn to implement and use
Grasp the concept and sequential, conditional, iterative, control structures in programs.
importance in programming. and branching structures.
What are Control Structures?
Control structures are fundamental programming concepts Types of Control Structures:
that control the flow of execution in a program.
• Sequential Control
They enable programs to make decisions, repeat tasks, or • Conditional Control (Selection)
execute code conditionally.
• Iterative Control (Loops)
• Branching Control
1. Sequential Control
Definition: Instructions are executed one after another in a linear order.
Example, like a morning routine.
Brush your teeth
Have breakfast
Pack your bag
Go to school
2. Conditional Control (Selection)
Definition: Conditional control allows programs to make decisions based on specific conditions.
Types of Conditional Statements:
If Statement
1 Executes code if condition is true
If-Else Statement
2 Provides alternative path if condition is false
Else-If Ladder
3 Checks multiple conditions in sequence
Conditional control allows programs to make decisions based on specific conditions.
Conditional Examples
If-Else Example Else-If Example Nested Conditions
age = 18 score = 85 if weather == "sunny":
if age >= 18: if score >= 90: if temperature > 25:
print("You can vote") print("Grade: A") print("Go
else: elif score >= 80: swimming")
print("Too young to print("Grade: B") else:
vote") else: print("Go hiking")
print("Grade: C")
3. Iterative Control (Loops)
Definition: Repeats a block of code multiple times.
For Loop While Loop
Repeats a known number of times. Repeats as long as a condition is true.
Example, Lets Print “Practice makes perfect” five times remind Example, While loop to print numbers from 1to 5
Over selves • The while loop will continue to execute as long as the
• range(5) generates numbers from 0 to 4 condition number <= 5 is true.
for i in range(5): number = 1
print("Practice makes perfect") while number <= 5:
print(number)
number += 1
4. Branching Control
Break Statement
Exits the loop immediately when a condition is met.
Continue Statement
Skips current iteration and moves to the next one.
Example
for i in range(10):
if i == 5:
break
print(i)
Summary
Sequential Conditional
Linear execution of instructions Decision-making based on conditions
Branching Iterative
Controlling flow within loops Repeating code multiple times
Practice using different control structures in simple programs to understand how they help in problem-solving.
Thank You !