SlideShare a Scribd company logo
1 of 11
Control flow statements:
The control flow statements in Python Programming Language are
1. Sequential Control Flow Statements: This refers to the line by line
execution, in which the statements are executed sequentially, in the same
order in which they appear in the program.
2. 2. Decision Control Flow Statements: Depending on whether a condition is
True or False, the decision structure may skip the execution of an entire
block of statements or even execute one block of statements instead of
other (if, if…else and if…elif…else).
3. Loop Control Flow Statements: This is a control structure that allows the
execution of a block of statements multiple times until a loop termination
condition is met (for loop and while loop).
• Loop Control Flow Statements are also called Repetition statements or
Iteration statements
Decision Control Flow Statements:
If
if –else
if – elif –else
If statement:
• The if decision control flow statement starts with if keyword
and ends with a colon.
• If the Boolean expression evaluates to True then statements
in the if block will be executed; otherwise the result is False then
none of the statements are executed.
Syntax:
if Boolean_ Expression:
statement (s)
For example,
a = 33
b = 200
if b > a:
print ("b is greater than a")
print ("done…")
Output:
b is greater than a
done…
if –else:
An if statement can also be followed by an else statement which is
optional.
An else statement does not have any condition.
Statements in the if block are executed if the Boolean Expression is
True.
Statements in the else block are executed if the Boolean Expression is
False.
The if…else statement allows for a two-way decision.
Syntax:
if Boolean Expression:
statement_1
else:
statement_2
Example:
age = int(input("Enter your age : "))
if age>=18:
print("You are eligible to vote !!")
else:
print("Sorry! you have to wait !!")
Output:
Enter your age: 19
You are eligible to vote!!
The if…elif…else Decision Control Statement
• The if…elif…else is also called as multi-way decision control statement.
When you need to choose from several possible alternatives, then an elif
statement is used along with an if statement.
•The keyword ‘elif’ is short for ‘else if’.
•The syntax for if…elif…else statement is,
if Boolean_Expression_1:
statement_1
elif Boolean_Expression_2:
statement_2
elif Boolean_Expression_3:
statement_3
:
else:
statement_last
• If Boolean_Expression_1 is True, then statement_1 is executed.
• If Boolean_Expression_1 is False and Boolean_Expression_2 is True, then state- ment_2 is
executed.
• If Boolean_Expression_1 and Boolean_Expression_2 are False and Boolean_ Expression_3 is
True, then statement_3 is executed and so on.
• If none of the Boolean_Expression is True, then statement_last is executed.
Example:
score = float(input("Enter your score"))
if score < 0 or score > 10:
print('Wrong Input')
elif score >= 9.0:
print('Your Grade is "A" ')
elif score >= 8.0:
print('Your Grade is "B" ')
elif score >= 7.0:
print('Your Grade is "C" ')
elif score >= 6.0:
print('Your Grade is "D" ')
else:
print('Your Grade is "F" ')
Output:
• Enter your score9.2
• Your Grade is "A“
Nested if Statement :
– An if statement that contains another if statement either in its
if block or else block is called a Nested if statement.
• The syntax of the nested if statement is,
•
If Boolean_Expression_1:
if Boolean_Expression_2:
statement_1
else:
statement_2
else:
statement_3
• If the Boolean_Expression_1 is evaluated to True, then the
control shifts to Boolean_ Expression_2 and if the expression
is evaluated to True, then statement_1 is executed, if the
Boolean_Expression_2 is evaluated to False then the
statement_2 is executed.
• If the Boolean_Expression_1 is evaluated to False, then
statement_3 is executed.
Loop Statements in Python :
• Sometimes we may need to alter the flow of the program. If
the execution of a specific code may need to be repeated
several numbers of times then we can go for loop statements.
• In python, the following are loop statements
o while loop
o for loop
while loop:
The syntax for while loop is,
while Boolean_Expression:
statement(s)
• The while loop starts with the while keyword and ends with a colon.
• If the Boolean expression evaluates to False, then the statements in
the while loop block are never executed.
• If the Boolean expression evaluates to True, then the while loop
block is executed. After each iteration of the loop block, the
Boolean expression is again checked, and if it is True, the loop is
iterated again.
• Each repetition of the loop block is called an iteration of the loop.
This process continues until the Boolean expression evaluates to
False.
• Execution then continues with the first statement after the while
loop.
Example:
i = 0
while i < 10:
print(f"Current value of i is {i}")
i = i + 1
OUTPUT
Current value of i is 0
Current value of i is 1
Current value of i is 2
Current value of i is 3
Current value of i is 4
Current value of i is 5
Current value of i is 6
Current value of i is 7
Current value of i is 8
Current value of i is 9
• The for Loop :
for iteration variable in sequence:
statement(s)
• The for loop starts with for keyword and ends with a colon. The first
item in the sequence gets assigned to the iteration variable. Here,
iteration variable can be any valid variable name.
• Then the statement block is executed. This process of assigning
items from the sequence to the iteration variable and then
executing the statement continues until all the items in the
sequence are completed.

More Related Content

Similar to Control_Statements.pptx

Similar to Control_Statements.pptx (20)

03 conditions loops
03   conditions loops03   conditions loops
03 conditions loops
 
Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
 
Computer programming 2 Lesson 9
Computer programming 2  Lesson 9Computer programming 2  Lesson 9
Computer programming 2 Lesson 9
 
Computer programming 2 - Lesson 7
Computer programming 2 - Lesson 7Computer programming 2 - Lesson 7
Computer programming 2 - Lesson 7
 
com.pptx
com.pptxcom.pptx
com.pptx
 
Loop and while Loop
Loop and while LoopLoop and while Loop
Loop and while Loop
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
cpu.pdf
cpu.pdfcpu.pdf
cpu.pdf
 
python conditional statement.pptx
python conditional statement.pptxpython conditional statement.pptx
python conditional statement.pptx
 
Java Repetiotion Statements
Java Repetiotion StatementsJava Repetiotion Statements
Java Repetiotion Statements
 
Learn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & LoopsLearn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & Loops
 
Iteration Statement in C++
Iteration Statement in C++Iteration Statement in C++
Iteration Statement in C++
 
W4-DecisionMaking.pdf. python document. CS
W4-DecisionMaking.pdf. python document. CSW4-DecisionMaking.pdf. python document. CS
W4-DecisionMaking.pdf. python document. CS
 
C language 2
C language 2C language 2
C language 2
 
Python Programming - Control Flow
Python Programming - Control Flow Python Programming - Control Flow
Python Programming - Control Flow
 
BSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETBSc. III Unit iii VB.NET
BSc. III Unit iii VB.NET
 
Control Statement IN C.pptx
Control Statement IN C.pptxControl Statement IN C.pptx
Control Statement IN C.pptx
 
C Programming - Decision making, Looping
C  Programming - Decision making, LoopingC  Programming - Decision making, Looping
C Programming - Decision making, Looping
 
C++ chapter 4
C++ chapter 4C++ chapter 4
C++ chapter 4
 
Chapter 4(1)
Chapter 4(1)Chapter 4(1)
Chapter 4(1)
 

More from Koteswari Kasireddy

Chapter-7-Sampling & sampling Distributions.pdf
Chapter-7-Sampling & sampling Distributions.pdfChapter-7-Sampling & sampling Distributions.pdf
Chapter-7-Sampling & sampling Distributions.pdfKoteswari Kasireddy
 
Object_Oriented_Programming_Unit3.pdf
Object_Oriented_Programming_Unit3.pdfObject_Oriented_Programming_Unit3.pdf
Object_Oriented_Programming_Unit3.pdfKoteswari Kasireddy
 
Relational Model and Relational Algebra.pptx
Relational Model and Relational Algebra.pptxRelational Model and Relational Algebra.pptx
Relational Model and Relational Algebra.pptxKoteswari Kasireddy
 
Unit 4 chapter - 8 Transaction processing Concepts (1).pptx
Unit 4 chapter - 8 Transaction processing Concepts (1).pptxUnit 4 chapter - 8 Transaction processing Concepts (1).pptx
Unit 4 chapter - 8 Transaction processing Concepts (1).pptxKoteswari Kasireddy
 
Database System Concepts AND architecture [Autosaved].pptx
Database System Concepts AND architecture [Autosaved].pptxDatabase System Concepts AND architecture [Autosaved].pptx
Database System Concepts AND architecture [Autosaved].pptxKoteswari Kasireddy
 
Control_Statements_in_Python.pptx
Control_Statements_in_Python.pptxControl_Statements_in_Python.pptx
Control_Statements_in_Python.pptxKoteswari Kasireddy
 
parts_of_python_programming_language.pptx
parts_of_python_programming_language.pptxparts_of_python_programming_language.pptx
parts_of_python_programming_language.pptxKoteswari Kasireddy
 

More from Koteswari Kasireddy (20)

DA Syllabus outline (2).pptx
DA Syllabus outline (2).pptxDA Syllabus outline (2).pptx
DA Syllabus outline (2).pptx
 
Chapter-7-Sampling & sampling Distributions.pdf
Chapter-7-Sampling & sampling Distributions.pdfChapter-7-Sampling & sampling Distributions.pdf
Chapter-7-Sampling & sampling Distributions.pdf
 
Object_Oriented_Programming_Unit3.pdf
Object_Oriented_Programming_Unit3.pdfObject_Oriented_Programming_Unit3.pdf
Object_Oriented_Programming_Unit3.pdf
 
unit-3_Chapter1_RDRA.pdf
unit-3_Chapter1_RDRA.pdfunit-3_Chapter1_RDRA.pdf
unit-3_Chapter1_RDRA.pdf
 
DBMS_UNIT_1.pdf
DBMS_UNIT_1.pdfDBMS_UNIT_1.pdf
DBMS_UNIT_1.pdf
 
business analytics
business analyticsbusiness analytics
business analytics
 
Relational Model and Relational Algebra.pptx
Relational Model and Relational Algebra.pptxRelational Model and Relational Algebra.pptx
Relational Model and Relational Algebra.pptx
 
CHAPTER -12 it.pptx
CHAPTER -12 it.pptxCHAPTER -12 it.pptx
CHAPTER -12 it.pptx
 
WEB_DATABASE_chapter_4.pptx
WEB_DATABASE_chapter_4.pptxWEB_DATABASE_chapter_4.pptx
WEB_DATABASE_chapter_4.pptx
 
Unit 4 chapter - 8 Transaction processing Concepts (1).pptx
Unit 4 chapter - 8 Transaction processing Concepts (1).pptxUnit 4 chapter - 8 Transaction processing Concepts (1).pptx
Unit 4 chapter - 8 Transaction processing Concepts (1).pptx
 
Database System Concepts AND architecture [Autosaved].pptx
Database System Concepts AND architecture [Autosaved].pptxDatabase System Concepts AND architecture [Autosaved].pptx
Database System Concepts AND architecture [Autosaved].pptx
 
Evolution Of WEB_students.pptx
Evolution Of WEB_students.pptxEvolution Of WEB_students.pptx
Evolution Of WEB_students.pptx
 
Presentation1.pptx
Presentation1.pptxPresentation1.pptx
Presentation1.pptx
 
Algorithm.pptx
Algorithm.pptxAlgorithm.pptx
Algorithm.pptx
 
Control_Statements_in_Python.pptx
Control_Statements_in_Python.pptxControl_Statements_in_Python.pptx
Control_Statements_in_Python.pptx
 
Python_Functions_Unit1.pptx
Python_Functions_Unit1.pptxPython_Functions_Unit1.pptx
Python_Functions_Unit1.pptx
 
parts_of_python_programming_language.pptx
parts_of_python_programming_language.pptxparts_of_python_programming_language.pptx
parts_of_python_programming_language.pptx
 
linked_list.pptx
linked_list.pptxlinked_list.pptx
linked_list.pptx
 
matrices_and_loops.pptx
matrices_and_loops.pptxmatrices_and_loops.pptx
matrices_and_loops.pptx
 
algorithms_in_linkedlist.pptx
algorithms_in_linkedlist.pptxalgorithms_in_linkedlist.pptx
algorithms_in_linkedlist.pptx
 

Recently uploaded

Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 

Recently uploaded (20)

Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 

Control_Statements.pptx

  • 1. Control flow statements: The control flow statements in Python Programming Language are 1. Sequential Control Flow Statements: This refers to the line by line execution, in which the statements are executed sequentially, in the same order in which they appear in the program. 2. 2. Decision Control Flow Statements: Depending on whether a condition is True or False, the decision structure may skip the execution of an entire block of statements or even execute one block of statements instead of other (if, if…else and if…elif…else). 3. Loop Control Flow Statements: This is a control structure that allows the execution of a block of statements multiple times until a loop termination condition is met (for loop and while loop). • Loop Control Flow Statements are also called Repetition statements or Iteration statements
  • 2. Decision Control Flow Statements: If if –else if – elif –else If statement: • The if decision control flow statement starts with if keyword and ends with a colon. • If the Boolean expression evaluates to True then statements in the if block will be executed; otherwise the result is False then none of the statements are executed. Syntax: if Boolean_ Expression: statement (s)
  • 3. For example, a = 33 b = 200 if b > a: print ("b is greater than a") print ("done…") Output: b is greater than a done… if –else: An if statement can also be followed by an else statement which is optional. An else statement does not have any condition. Statements in the if block are executed if the Boolean Expression is True. Statements in the else block are executed if the Boolean Expression is False. The if…else statement allows for a two-way decision.
  • 4. Syntax: if Boolean Expression: statement_1 else: statement_2 Example: age = int(input("Enter your age : ")) if age>=18: print("You are eligible to vote !!") else: print("Sorry! you have to wait !!") Output: Enter your age: 19 You are eligible to vote!!
  • 5. The if…elif…else Decision Control Statement • The if…elif…else is also called as multi-way decision control statement. When you need to choose from several possible alternatives, then an elif statement is used along with an if statement. •The keyword ‘elif’ is short for ‘else if’. •The syntax for if…elif…else statement is, if Boolean_Expression_1: statement_1 elif Boolean_Expression_2: statement_2 elif Boolean_Expression_3: statement_3 : else: statement_last
  • 6. • If Boolean_Expression_1 is True, then statement_1 is executed. • If Boolean_Expression_1 is False and Boolean_Expression_2 is True, then state- ment_2 is executed. • If Boolean_Expression_1 and Boolean_Expression_2 are False and Boolean_ Expression_3 is True, then statement_3 is executed and so on. • If none of the Boolean_Expression is True, then statement_last is executed. Example: score = float(input("Enter your score")) if score < 0 or score > 10: print('Wrong Input') elif score >= 9.0: print('Your Grade is "A" ') elif score >= 8.0: print('Your Grade is "B" ') elif score >= 7.0: print('Your Grade is "C" ') elif score >= 6.0: print('Your Grade is "D" ') else: print('Your Grade is "F" ')
  • 7. Output: • Enter your score9.2 • Your Grade is "A“ Nested if Statement : – An if statement that contains another if statement either in its if block or else block is called a Nested if statement. • The syntax of the nested if statement is, • If Boolean_Expression_1: if Boolean_Expression_2: statement_1 else: statement_2 else: statement_3
  • 8. • If the Boolean_Expression_1 is evaluated to True, then the control shifts to Boolean_ Expression_2 and if the expression is evaluated to True, then statement_1 is executed, if the Boolean_Expression_2 is evaluated to False then the statement_2 is executed. • If the Boolean_Expression_1 is evaluated to False, then statement_3 is executed. Loop Statements in Python : • Sometimes we may need to alter the flow of the program. If the execution of a specific code may need to be repeated several numbers of times then we can go for loop statements. • In python, the following are loop statements o while loop o for loop
  • 9. while loop: The syntax for while loop is, while Boolean_Expression: statement(s) • The while loop starts with the while keyword and ends with a colon. • If the Boolean expression evaluates to False, then the statements in the while loop block are never executed. • If the Boolean expression evaluates to True, then the while loop block is executed. After each iteration of the loop block, the Boolean expression is again checked, and if it is True, the loop is iterated again. • Each repetition of the loop block is called an iteration of the loop. This process continues until the Boolean expression evaluates to False. • Execution then continues with the first statement after the while loop.
  • 10. Example: i = 0 while i < 10: print(f"Current value of i is {i}") i = i + 1 OUTPUT Current value of i is 0 Current value of i is 1 Current value of i is 2 Current value of i is 3 Current value of i is 4 Current value of i is 5 Current value of i is 6 Current value of i is 7 Current value of i is 8 Current value of i is 9
  • 11. • The for Loop : for iteration variable in sequence: statement(s) • The for loop starts with for keyword and ends with a colon. The first item in the sequence gets assigned to the iteration variable. Here, iteration variable can be any valid variable name. • Then the statement block is executed. This process of assigning items from the sequence to the iteration variable and then executing the statement continues until all the items in the sequence are completed.