SlideShare a Scribd company logo
Python Flow Control
Python if...else
Python for Loop
Python while Loop
Python break and continue
Python Pass
Python if...else
• What are if statement in Python?
• Python if Statement Syntax
• Python if Statement Flowchart
• Example: Python if Statement
• Python if...else Statement
• Syntax of if...else
• Python if..else Flowchart
• Example of if...else
• Python if...elif...else Statement
• Syntax of if...elif...else
• Flowchart of if...elif...else
• Example of if...elif...else
• Python Nested if statements
Python if Statement Syntax
• Syntax
Python if Statement Flowchart
Example:
Output
Syntax of if...else
• Syntax
Python if..else Flowchart
Example of if...else
Output
Syntax of if...elif...else
• Syntax
Flowchart of if...elif...else
Example of if...elif...else
Output
Python Nested if statements
Output
Python for Loop
• What is for loop in Python?
• Syntax of for Loop
• Flowchart of for loop
• Example: Python for Loop
• The range() function
• for loop with else
What is for loop in Python?
• Is used to iterate over a sequence (list, tuple, string) or other iterable
objects
• Iterating over a sequence is called traversal
• Syntax of for Loop:
• Here, val is the variable that takes the value of the item inside the
sequence on each iteration
• Loop continues until we reach the last item in the sequence. The body
of for loop is separated from the rest of the code using indentation.
Flowchart of for Loop
Example
Python Flow Control
The range() function
• Can generate a sequence of numbers using range() function
• range(10) will generate numbers from 0 to 9 (10 numbers)
• Can also define the start, stop and step size as
range(start,stop,stepsize)
• Step size defaults to 1 if not provided.
• Does not store all the values in memory, it would be inefficient
• So it remembers the start, stop, step size and generates the next
number on the go
Example
Python Flow Control
for loop with else
Python while Loop
• What is while loop in Python?
• Syntax of while Loop in Python
• Flowchart of while loop
• Example: Python while Loop
• while loop with else
What is while loop in Python?
• Is used to iterate over a block of code as long as the test expression
(condition) is true
• Generally this loop is used when we don't know beforehand, the
number of times to iterate
Syntax of while Loop in Python
• Python interprets any non-zero value as True. None and 0 are
interpreted as False.
Flowchart of while Loop
Example
Python Flow Control
while loop with else
Python Flow Control
Python break and continue
• What is the use of break and continue in Python?
• Python break statement
• Syntax of break
• Flowchart of break
• Example of break
• Python continue statement
• Syntax of Continue
• Flowchart of continue
• Example: Python continue
What is the use of break and continue in
Python?
• break and continue statements can alter the flow of a normal loop
• Loops iterate over a block of code until test expression is false, but
sometimes we wish to terminate the current iteration or even the
whole loop without checking test expression
• break and continue statements are used in these cases
Python break statement
• Terminates the loop containing it
• Control of the program flows to the statement immediately after the
body of the loop.
• If break statement is inside a nested loop (loop inside another loop),
break will terminate the innermost loop
• Syntax of break
Flowchart of break
Example
Python Flow Control
Python continue statement
• Is used to skip the rest of the code inside a loop for the current
iteration only
• Loop does not terminate but continues on with the next iteration
• Syntax of Continue
Flowchart of continue
Example
Python Flow Control
Python pass statement
• What is pass statement in Python?
• Syntax of pass
• Example: pass Statement
What is pass statement in Python?
• pass is a null statement
• The difference between a comment and pass statement in Python is
that, while the interpreter ignores a comment entirely, pass is not
ignored
• However, nothing happens when pass is executed
• It results into no operation (NOP)
• Syntax of pass
Example
Example
Thank You !

More Related Content

PDF
File handling in Python
BMS Institute of Technology and Management
 
PDF
Introduction to Python
Mohammed Sikander
 
PPTX
Python
Gagandeep Nanda
 
PPTX
Python Operators
Adheetha O. V
 
PPTX
Conditionalstatement
RaginiJain21
 
PPTX
PART 1 - Python Tutorial | Variables and Data Types in Python
Shivam Mitra
 
PDF
Python If Else | If Else Statement In Python | Edureka
Edureka!
 
PPTX
Python Datatypes by SujithKumar
Sujith Kumar
 
Introduction to Python
Mohammed Sikander
 
Python Operators
Adheetha O. V
 
Conditionalstatement
RaginiJain21
 
PART 1 - Python Tutorial | Variables and Data Types in Python
Shivam Mitra
 
Python If Else | If Else Statement In Python | Edureka
Edureka!
 
Python Datatypes by SujithKumar
Sujith Kumar
 

What's hot (20)

PPT
Python ppt
Mohita Pandey
 
PPTX
Abstract Data Types
karthikeyanC40
 
PDF
Variables & Data Types In Python | Edureka
Edureka!
 
PPTX
Python | What is Python | History of Python | Python Tutorial
QA TrainingHub
 
PDF
Python Flow Control
Mohammed Sikander
 
PPTX
Chapter 05 classes and objects
Praveen M Jigajinni
 
PPSX
Modules and packages in python
TMARAGATHAM
 
PPTX
Linked List - Insertion & Deletion
Afaq Mansoor Khan
 
PPTX
Asymptotic Notation
Protap Mondal
 
PPTX
Functions in c language
tanmaymodi4
 
PPTX
Python Functions
Mohammed Sikander
 
PPTX
Looping Statements and Control Statements in Python
PriyankaC44
 
PDF
Python programming : Control statements
Emertxe Information Technologies Pvt Ltd
 
PPTX
Fundamentals of Python Programming
Kamal Acharya
 
PPTX
Function Pointer
Dr-Dipali Meher
 
PPSX
Programming with Python
Rasan Samarasinghe
 
PDF
Set methods in python
deepalishinkar1
 
PPT
Object-oriented concepts
BG Java EE Course
 
PPTX
C Programming: Control Structure
Sokngim Sa
 
PPTX
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Maulik Borsaniya
 
Python ppt
Mohita Pandey
 
Abstract Data Types
karthikeyanC40
 
Variables & Data Types In Python | Edureka
Edureka!
 
Python | What is Python | History of Python | Python Tutorial
QA TrainingHub
 
Python Flow Control
Mohammed Sikander
 
Chapter 05 classes and objects
Praveen M Jigajinni
 
Modules and packages in python
TMARAGATHAM
 
Linked List - Insertion & Deletion
Afaq Mansoor Khan
 
Asymptotic Notation
Protap Mondal
 
Functions in c language
tanmaymodi4
 
Python Functions
Mohammed Sikander
 
Looping Statements and Control Statements in Python
PriyankaC44
 
Python programming : Control statements
Emertxe Information Technologies Pvt Ltd
 
Fundamentals of Python Programming
Kamal Acharya
 
Function Pointer
Dr-Dipali Meher
 
Programming with Python
Rasan Samarasinghe
 
Set methods in python
deepalishinkar1
 
Object-oriented concepts
BG Java EE Course
 
C Programming: Control Structure
Sokngim Sa
 
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Maulik Borsaniya
 
Ad

Similar to Python Flow Control (20)

PPTX
Python if_else_loop_Control_Flow_Statement
AbhishekGupta692777
 
PPTX
Types of Statements in Python Programming Language
Explore Skilled
 
PPT
PPT3-CONDITIONAL STATEMENT LOOPS DICTIONARY FUNCTIONS.ppt
RahulKumar812056
 
PPTX
6 Iterative Statements.pptx
ssuser8e50d8
 
PPT
ppt3-conditionalstatementloopsdictionaryfunctions-240731050730-455ba0fa.ppt
avishekpradhan24
 
PPTX
While_for_loop presententationin first year students
SIHIGOPAL
 
PDF
While-For-loop in python used in college
ssuser7a7cd61
 
PDF
PYTHON FULL TUTORIAL WITH PROGRAMMS
Aniruddha Paul
 
DOCX
iterations.docx
ssuser2e84e4
 
PDF
ch2 Python flow control.pdf
RanjanaThakuria1
 
PPTX
PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT 2
MulliMary
 
PPTX
Module_2_1_Building Python Programs_Final.pptx
nikhithavarghese77
 
PDF
E-Notes_3721_Content_Document_20250107032537PM.pdf
aayushihirpara297
 
PPT
Python session3
Aswin Krishnamoorthy
 
PPTX
break continue and pass in python progran.pptx
urvashipundir04
 
PPTX
a1 this is in python that has break continue and pass.pptx
urvashipundir04
 
PPTX
Chapter 2-Python and control flow statement.pptx
atharvdeshpande20
 
PPTX
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...
jaychoudhary37
 
PPTX
This is all about control flow in python intruducing the Break and Continue.pptx
elezearrepil1
 
Python if_else_loop_Control_Flow_Statement
AbhishekGupta692777
 
Types of Statements in Python Programming Language
Explore Skilled
 
PPT3-CONDITIONAL STATEMENT LOOPS DICTIONARY FUNCTIONS.ppt
RahulKumar812056
 
6 Iterative Statements.pptx
ssuser8e50d8
 
ppt3-conditionalstatementloopsdictionaryfunctions-240731050730-455ba0fa.ppt
avishekpradhan24
 
While_for_loop presententationin first year students
SIHIGOPAL
 
While-For-loop in python used in college
ssuser7a7cd61
 
PYTHON FULL TUTORIAL WITH PROGRAMMS
Aniruddha Paul
 
iterations.docx
ssuser2e84e4
 
ch2 Python flow control.pdf
RanjanaThakuria1
 
PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT 2
MulliMary
 
Module_2_1_Building Python Programs_Final.pptx
nikhithavarghese77
 
E-Notes_3721_Content_Document_20250107032537PM.pdf
aayushihirpara297
 
Python session3
Aswin Krishnamoorthy
 
break continue and pass in python progran.pptx
urvashipundir04
 
a1 this is in python that has break continue and pass.pptx
urvashipundir04
 
Chapter 2-Python and control flow statement.pptx
atharvdeshpande20
 
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...
jaychoudhary37
 
This is all about control flow in python intruducing the Break and Continue.pptx
elezearrepil1
 
Ad

More from Kamal Acharya (20)

PPTX
Programming the basic computer
Kamal Acharya
 
PPTX
Computer Arithmetic
Kamal Acharya
 
PPTX
Introduction to Computer Security
Kamal Acharya
 
PPTX
Session and Cookies
Kamal Acharya
 
PPTX
Functions in php
Kamal Acharya
 
PPTX
Web forms in php
Kamal Acharya
 
PPTX
Making decision and repeating in PHP
Kamal Acharya
 
PPTX
Working with arrays in php
Kamal Acharya
 
PPTX
Text and Numbers (Data Types)in PHP
Kamal Acharya
 
PPTX
Introduction to PHP
Kamal Acharya
 
PPTX
Capacity Planning of Data Warehousing
Kamal Acharya
 
PPTX
Data Warehousing
Kamal Acharya
 
PPTX
Search Engines
Kamal Acharya
 
PPTX
Web Mining
Kamal Acharya
 
PPTX
Information Privacy and Data Mining
Kamal Acharya
 
PPTX
Cluster Analysis
Kamal Acharya
 
PPTX
Association Analysis in Data Mining
Kamal Acharya
 
PPTX
Classification techniques in data mining
Kamal Acharya
 
PPTX
Data Preprocessing
Kamal Acharya
 
PPTX
Introduction to Data Mining and Data Warehousing
Kamal Acharya
 
Programming the basic computer
Kamal Acharya
 
Computer Arithmetic
Kamal Acharya
 
Introduction to Computer Security
Kamal Acharya
 
Session and Cookies
Kamal Acharya
 
Functions in php
Kamal Acharya
 
Web forms in php
Kamal Acharya
 
Making decision and repeating in PHP
Kamal Acharya
 
Working with arrays in php
Kamal Acharya
 
Text and Numbers (Data Types)in PHP
Kamal Acharya
 
Introduction to PHP
Kamal Acharya
 
Capacity Planning of Data Warehousing
Kamal Acharya
 
Data Warehousing
Kamal Acharya
 
Search Engines
Kamal Acharya
 
Web Mining
Kamal Acharya
 
Information Privacy and Data Mining
Kamal Acharya
 
Cluster Analysis
Kamal Acharya
 
Association Analysis in Data Mining
Kamal Acharya
 
Classification techniques in data mining
Kamal Acharya
 
Data Preprocessing
Kamal Acharya
 
Introduction to Data Mining and Data Warehousing
Kamal Acharya
 

Recently uploaded (20)

PPTX
Congenital Hypothyroidism pptx
AneetaSharma15
 
PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PDF
7.Particulate-Nature-of-Matter.ppt/8th class science curiosity/by k sandeep s...
Sandeep Swamy
 
PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PPTX
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
PPT
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
PDF
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PDF
Wings of Fire Book by Dr. A.P.J Abdul Kalam Full PDF
hetalvaishnav93
 
PPTX
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
PDF
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PPTX
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PDF
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PDF
Landforms and landscapes data surprise preview
jpinnuck
 
PDF
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
PPTX
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
RAKESH SAJJAN
 
Congenital Hypothyroidism pptx
AneetaSharma15
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
7.Particulate-Nature-of-Matter.ppt/8th class science curiosity/by k sandeep s...
Sandeep Swamy
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
Wings of Fire Book by Dr. A.P.J Abdul Kalam Full PDF
hetalvaishnav93
 
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
Landforms and landscapes data surprise preview
jpinnuck
 
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
RAKESH SAJJAN
 

Python Flow Control

  • 1. Python Flow Control Python if...else Python for Loop Python while Loop Python break and continue Python Pass
  • 2. Python if...else • What are if statement in Python? • Python if Statement Syntax • Python if Statement Flowchart • Example: Python if Statement • Python if...else Statement • Syntax of if...else • Python if..else Flowchart • Example of if...else • Python if...elif...else Statement • Syntax of if...elif...else • Flowchart of if...elif...else • Example of if...elif...else • Python Nested if statements
  • 3. Python if Statement Syntax • Syntax
  • 15. Python Nested if statements
  • 17. Python for Loop • What is for loop in Python? • Syntax of for Loop • Flowchart of for loop • Example: Python for Loop • The range() function • for loop with else
  • 18. What is for loop in Python? • Is used to iterate over a sequence (list, tuple, string) or other iterable objects • Iterating over a sequence is called traversal
  • 19. • Syntax of for Loop: • Here, val is the variable that takes the value of the item inside the sequence on each iteration • Loop continues until we reach the last item in the sequence. The body of for loop is separated from the rest of the code using indentation.
  • 23. The range() function • Can generate a sequence of numbers using range() function • range(10) will generate numbers from 0 to 9 (10 numbers) • Can also define the start, stop and step size as range(start,stop,stepsize) • Step size defaults to 1 if not provided. • Does not store all the values in memory, it would be inefficient • So it remembers the start, stop, step size and generates the next number on the go
  • 27. Python while Loop • What is while loop in Python? • Syntax of while Loop in Python • Flowchart of while loop • Example: Python while Loop • while loop with else
  • 28. What is while loop in Python? • Is used to iterate over a block of code as long as the test expression (condition) is true • Generally this loop is used when we don't know beforehand, the number of times to iterate
  • 29. Syntax of while Loop in Python • Python interprets any non-zero value as True. None and 0 are interpreted as False.
  • 35. Python break and continue • What is the use of break and continue in Python? • Python break statement • Syntax of break • Flowchart of break • Example of break • Python continue statement • Syntax of Continue • Flowchart of continue • Example: Python continue
  • 36. What is the use of break and continue in Python? • break and continue statements can alter the flow of a normal loop • Loops iterate over a block of code until test expression is false, but sometimes we wish to terminate the current iteration or even the whole loop without checking test expression • break and continue statements are used in these cases
  • 37. Python break statement • Terminates the loop containing it • Control of the program flows to the statement immediately after the body of the loop. • If break statement is inside a nested loop (loop inside another loop), break will terminate the innermost loop • Syntax of break
  • 41. Python continue statement • Is used to skip the rest of the code inside a loop for the current iteration only • Loop does not terminate but continues on with the next iteration • Syntax of Continue
  • 45. Python pass statement • What is pass statement in Python? • Syntax of pass • Example: pass Statement
  • 46. What is pass statement in Python? • pass is a null statement • The difference between a comment and pass statement in Python is that, while the interpreter ignores a comment entirely, pass is not ignored • However, nothing happens when pass is executed • It results into no operation (NOP) • Syntax of pass