SlideShare a Scribd company logo
Looping statements
A loop statement allows us to execute a statement
or group of statements multiple times.
Looping statements
Types of Looping statements
For loop
While
loop
Nested
loop
For Loop
The for loop in python is
used to iterate the
statements or part of
the program several
times. It is frequently
used to traverse the
data structures like list,
tuple, or dictionary.
Flowchart
for iterating_var in sequence:
statements
Syntax
Write a
program to
print 1 to 10
series
i=1
For i in range(0,11):
Print(i)
Output
0 1 2 3 4 5 6 7 8 9
Example
To print
multiplication table
i=0
n=int(input("enter no"))
for i in range(0,11):
print("%d X %d = %d" %
(n,i,n*i))
enter no 6
6 X 0 = 0
6 X 1 = 6
6 X 2 = 12
6 X 3 = 18
6 X 4 = 24
6 X 5 = 30
6 X 6 = 36
6 X 7 = 42
6 X 8 = 48
6 X 9 = 54
6 X 10 = 60
Output
Program
to
Iterating
string
using for
loop
str = "Python"
for i in str:
print(i)
P
Y
T
H
O
N
Output
Example
Program to iterate through a
list using indexing
city = ['Bhopal', 'Indore', 'Gwalior',
'Ujjain', 'Sagar‘]
# iterate over the list using index
for i in range(len(city)):
print("I go to", city[i])
I go to Bhopal
I go to Indore
I go to Gwalior
I go to Ujjain
I go to Sagar
Output Example
While loop syntax
while (
test_expression):
Body of while
Repeats a statement or
group of statements while
a given condition is TRUE. It
tests the condition before
executing the loop body.
Flow chart
i = 1
while i < 6:
print(i)
i += 1
1
2
3
4
5
Output
Example
Program to
print 1 to 5
series
a =[‘student1', ‘student2',
‘student3']
while a:
(a.pop(-1))
Student3
Student2
Student1
Program to print list in reverse order
Example Output
10
9
8
7
6
5
4
3
2
1
Example
Output
n=10
while n > 0:
n -= 1;
if True: print(n)
Using if Statement with While Loop
Using else Statement with While Loop
Python supports to have
an else statement associated with a
loop statement.
If the else statement is used with
a while loop, the else statement is
executed when the condition becomes
false.
Syntax
while expr:
statement(s)
else:
additional_statement(s)
count = 0
while count < 5:
print count, " is
less than 5"
count = count + 1
else:
print count, " is
not less than 5"
0 is less than 5
1 is less than 5
2 is less than 5
3 is less than 5
4 is less than 5
5 is not less than 5
Program to print
series with else state
Example
Output
Find Even odd no
number = 2
while number < 10 :
# Find the mod of 2
if number%2 == 0:
print("The number
"+str(number)+" is even")
else:
print("The number
"+str(number)+" is odd")
# Increment `number` by 1
number = number+1
The number 2 is even
The number 3 is odd
The number 4 is even
The number 5 is odd
The number 6 is even
The number 7 is odd
The number 8 is even
The number 9 is odd
Output
Nested loop
2
3
5
7
11
13
prime no
i = 2
print("prime no")
while(i < 15):
j = 2
while(j <= (i/j)):
if not(i%j): break
j = j + 1
if (j > i/j) : print(i)
i = i + 1
You can use one or more
loop inside any another
while, for or do..while
loop.
Example
Program to
print given
pattern
5 4 3 2 1
5 4 3 2
5 4 3
5 4
5
while(i<=5):
j=5
while(j>=i):
print(j, end=' ‘)
j-=1
i+=1
print()
Output
Example
program to
print given
below
pattern
*
**
***
****
*****
rows = int(input("Enter the rows:"))
# Outer loop will print number of ro
ws
for i in range(0,rows+1):
# Inner loop will print number of Ast
risk
for j in range(i):
print("*",end = '')
print()
Example
Program to print
given pattern
1
22
333
4444
55555
rows = int(input("Enter the
rows"))
for i in range(0,rows+1):
for j in range(i):
print(i,end = '')
print()
For more presentation
contact us
raginijain0208@gmail.com
Looping statement in python

More Related Content

What's hot (20)

PPTX
Python Functions
Mohammed Sikander
 
PPTX
Functions in Python
Kamal Acharya
 
PPTX
Control statements in c
Sathish Narayanan
 
PPTX
Conditional Statement in C Language
Shaina Arora
 
PPT
Introduction to Python
Nowell Strite
 
PPT
File handling in c
David Livingston J
 
PPTX
Variables in python
Jaya Kumari
 
PPT
Class and object in C++
rprajat007
 
PDF
Datatypes in python
eShikshak
 
PPTX
control statements in python.pptx
Anshu Varma
 
PPTX
Presentation on array
topu93
 
PPTX
Loops in C Programming Language
Mahantesh Devoor
 
PPTX
STACKS IN DATASTRUCTURE
Archie Jamwal
 
PPT
Arrays
SARITHA REDDY
 
PPTX
Basics of Object Oriented Programming in Python
Sujith Kumar
 
PPTX
Beginning Python Programming
St. Petersburg College
 
PPTX
Looping Statements and Control Statements in Python
PriyankaC44
 
PPTX
Inheritance in c++
Vineeta Garg
 
PDF
Python final ppt
Ripal Ranpara
 
PPTX
Graph in data structure
Abrish06
 
Python Functions
Mohammed Sikander
 
Functions in Python
Kamal Acharya
 
Control statements in c
Sathish Narayanan
 
Conditional Statement in C Language
Shaina Arora
 
Introduction to Python
Nowell Strite
 
File handling in c
David Livingston J
 
Variables in python
Jaya Kumari
 
Class and object in C++
rprajat007
 
Datatypes in python
eShikshak
 
control statements in python.pptx
Anshu Varma
 
Presentation on array
topu93
 
Loops in C Programming Language
Mahantesh Devoor
 
STACKS IN DATASTRUCTURE
Archie Jamwal
 
Basics of Object Oriented Programming in Python
Sujith Kumar
 
Beginning Python Programming
St. Petersburg College
 
Looping Statements and Control Statements in Python
PriyankaC44
 
Inheritance in c++
Vineeta Garg
 
Python final ppt
Ripal Ranpara
 
Graph in data structure
Abrish06
 

Similar to Looping statement in python (20)

PDF
loopingstatementinpython-210628184047 (1).pdf
DheeravathBinduMadha
 
PPTX
loopin gstatement in python using .pptx
urvashipundir04
 
PPTX
module 3 BTECH FIRST YEAR ATP APJ KTU PYTHON
FahmaFamzin
 
PPTX
Chapter 2-Python and control flow statement.pptx
atharvdeshpande20
 
PPTX
Python notes for students to learn and develop
kavithaadhilakshmi
 
PPTX
industry coding practice unit-2 ppt.pptx
LakshmiMarineni
 
PPTX
Loops in Python.pptx
Guru Nanak Dev University, Amritsar
 
PPT
Python Control structures
Siddique Ibrahim
 
PDF
pythonQuick.pdf
PhanMinhLinhAnxM0190
 
PDF
python notes.pdf
RohitSindhu10
 
PDF
python 34💭.pdf
AkashdeepBhattacharj1
 
PDF
Python Decision Making And Loops.pdf
NehaSpillai1
 
PDF
04-Looping( For , while and do while looping) .pdf
nithishkumar2867
 
PPTX
1. control structures in the python.pptx
DURAIMURUGANM2
 
PDF
2 Python Basics II meeting 2 tunghai university pdf
Anggi Andriyadi
 
PPTX
TN 12 computer Science - ppt CHAPTER-6.pptx
knmschool
 
PPTX
Control structure of c
Komal Kotak
 
PDF
loops.pdf
AmayJaiswal4
 
PDF
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
DR B.Surendiran .
 
PPTX
Loops in Python
Arockia Abins
 
loopingstatementinpython-210628184047 (1).pdf
DheeravathBinduMadha
 
loopin gstatement in python using .pptx
urvashipundir04
 
module 3 BTECH FIRST YEAR ATP APJ KTU PYTHON
FahmaFamzin
 
Chapter 2-Python and control flow statement.pptx
atharvdeshpande20
 
Python notes for students to learn and develop
kavithaadhilakshmi
 
industry coding practice unit-2 ppt.pptx
LakshmiMarineni
 
Python Control structures
Siddique Ibrahim
 
pythonQuick.pdf
PhanMinhLinhAnxM0190
 
python notes.pdf
RohitSindhu10
 
python 34💭.pdf
AkashdeepBhattacharj1
 
Python Decision Making And Loops.pdf
NehaSpillai1
 
04-Looping( For , while and do while looping) .pdf
nithishkumar2867
 
1. control structures in the python.pptx
DURAIMURUGANM2
 
2 Python Basics II meeting 2 tunghai university pdf
Anggi Andriyadi
 
TN 12 computer Science - ppt CHAPTER-6.pptx
knmschool
 
Control structure of c
Komal Kotak
 
loops.pdf
AmayJaiswal4
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
DR B.Surendiran .
 
Loops in Python
Arockia Abins
 
Ad

More from RaginiJain21 (7)

PPTX
Jump statment in python
RaginiJain21
 
PPTX
Conditionalstatement
RaginiJain21
 
PPTX
Python media library
RaginiJain21
 
PPTX
Basic python programs
RaginiJain21
 
PPTX
Python Libraries and Modules
RaginiJain21
 
PPTX
Python second ppt
RaginiJain21
 
PPTX
Final presentation on python
RaginiJain21
 
Jump statment in python
RaginiJain21
 
Conditionalstatement
RaginiJain21
 
Python media library
RaginiJain21
 
Basic python programs
RaginiJain21
 
Python Libraries and Modules
RaginiJain21
 
Python second ppt
RaginiJain21
 
Final presentation on python
RaginiJain21
 
Ad

Recently uploaded (20)

PDF
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
Introduction to Indian Writing in English
Trushali Dodiya
 
PPTX
TRANSLATIONAL AND ROTATIONAL MOTION.pptx
KIPAIZAGABAWA1
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
STATEMENT-BY-THE-HON.-MINISTER-FOR-HEALTH-ON-THE-COVID-19-OUTBREAK-AT-UG_revi...
nservice241
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
Council of Chalcedon Re-Examined
Smiling Lungs
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PDF
epi editorial commitee meeting presentation
MIPLM
 
PDF
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PDF
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
PPTX
infertility, types,causes, impact, and management
Ritu480198
 
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Introduction to Indian Writing in English
Trushali Dodiya
 
TRANSLATIONAL AND ROTATIONAL MOTION.pptx
KIPAIZAGABAWA1
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
STATEMENT-BY-THE-HON.-MINISTER-FOR-HEALTH-ON-THE-COVID-19-OUTBREAK-AT-UG_revi...
nservice241
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Council of Chalcedon Re-Examined
Smiling Lungs
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
epi editorial commitee meeting presentation
MIPLM
 
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
infertility, types,causes, impact, and management
Ritu480198
 

Looping statement in python

  • 2. A loop statement allows us to execute a statement or group of statements multiple times. Looping statements
  • 3. Types of Looping statements For loop While loop Nested loop
  • 4. For Loop The for loop in python is used to iterate the statements or part of the program several times. It is frequently used to traverse the data structures like list, tuple, or dictionary.
  • 6. for iterating_var in sequence: statements Syntax
  • 7. Write a program to print 1 to 10 series i=1 For i in range(0,11): Print(i) Output 0 1 2 3 4 5 6 7 8 9 Example
  • 8. To print multiplication table i=0 n=int(input("enter no")) for i in range(0,11): print("%d X %d = %d" % (n,i,n*i)) enter no 6 6 X 0 = 0 6 X 1 = 6 6 X 2 = 12 6 X 3 = 18 6 X 4 = 24 6 X 5 = 30 6 X 6 = 36 6 X 7 = 42 6 X 8 = 48 6 X 9 = 54 6 X 10 = 60 Output
  • 9. Program to Iterating string using for loop str = "Python" for i in str: print(i) P Y T H O N Output Example
  • 10. Program to iterate through a list using indexing city = ['Bhopal', 'Indore', 'Gwalior', 'Ujjain', 'Sagar‘] # iterate over the list using index for i in range(len(city)): print("I go to", city[i]) I go to Bhopal I go to Indore I go to Gwalior I go to Ujjain I go to Sagar Output Example
  • 11. While loop syntax while ( test_expression): Body of while Repeats a statement or group of statements while a given condition is TRUE. It tests the condition before executing the loop body.
  • 13. i = 1 while i < 6: print(i) i += 1 1 2 3 4 5 Output Example Program to print 1 to 5 series
  • 14. a =[‘student1', ‘student2', ‘student3'] while a: (a.pop(-1)) Student3 Student2 Student1 Program to print list in reverse order Example Output
  • 15. 10 9 8 7 6 5 4 3 2 1 Example Output n=10 while n > 0: n -= 1; if True: print(n) Using if Statement with While Loop
  • 16. Using else Statement with While Loop Python supports to have an else statement associated with a loop statement. If the else statement is used with a while loop, the else statement is executed when the condition becomes false.
  • 18. count = 0 while count < 5: print count, " is less than 5" count = count + 1 else: print count, " is not less than 5" 0 is less than 5 1 is less than 5 2 is less than 5 3 is less than 5 4 is less than 5 5 is not less than 5 Program to print series with else state Example Output
  • 19. Find Even odd no number = 2 while number < 10 : # Find the mod of 2 if number%2 == 0: print("The number "+str(number)+" is even") else: print("The number "+str(number)+" is odd") # Increment `number` by 1 number = number+1 The number 2 is even The number 3 is odd The number 4 is even The number 5 is odd The number 6 is even The number 7 is odd The number 8 is even The number 9 is odd Output
  • 20. Nested loop 2 3 5 7 11 13 prime no i = 2 print("prime no") while(i < 15): j = 2 while(j <= (i/j)): if not(i%j): break j = j + 1 if (j > i/j) : print(i) i = i + 1 You can use one or more loop inside any another while, for or do..while loop. Example
  • 21. Program to print given pattern 5 4 3 2 1 5 4 3 2 5 4 3 5 4 5 while(i<=5): j=5 while(j>=i): print(j, end=' ‘) j-=1 i+=1 print() Output Example
  • 22. program to print given below pattern * ** *** **** ***** rows = int(input("Enter the rows:")) # Outer loop will print number of ro ws for i in range(0,rows+1): # Inner loop will print number of Ast risk for j in range(i): print("*",end = '') print() Example
  • 23. Program to print given pattern 1 22 333 4444 55555 rows = int(input("Enter the rows")) for i in range(0,rows+1): for j in range(i): print(i,end = '') print()