SlideShare a Scribd company logo
7
Most read
10
Most read
12
Most read
www.edureka.co/pythonEDUREKA PYTHON CERTIFICATION TRAINING
Python Loops
www.edureka.co/pythonEDUREKA PYTHON CERTIFICATION TRAINING
Agenda
āž¢ Why to use loops
āž¢ What are loops
āž¢ Types of loops in Python
ā–Ŗ While
ā–Ŗ For
ā–Ŗ Nested
āž¢ Summary
www.edureka.co/pythonEDUREKA PYTHON CERTIFICATION TRAINING
Why To Use Loops?
www.edureka.co/pythonEDUREKA PYTHON CERTIFICATION TRAINING
Why To Use Loops
If a software developer develops a software module for payroll processing
that needs to compute the salaries and the bonus of all the employees.
Software module
for payroll
processing
Salary
Bonus
Total
Employee - 1
Employee - 2
Employee - 3
www.edureka.co/pythonEDUREKA PYTHON CERTIFICATION TRAINING
Why To Use Loops
Manual Loops
Employee-1:
Salary
Bonus
Total
Employee-2:
Salary
Bonus
Total
Employee-3:
Salary
Bonus
Total
Start
Logic to calculate
the total salary
Employee-1:
Salary
Bonus
Total
Start
Logic to calculate
salary of
Employee-1
Employee-2:
Salary
Bonus
Total
Start
Logic to calculate
salary of
Employee-2
Employee-3:
Salary
Bonus
Total
Start
Logic to calculate
salary of
Employee-3
www.edureka.co/pythonEDUREKA PYTHON CERTIFICATION TRAINING
What are Loops?
www.edureka.co/pythonEDUREKA PYTHON CERTIFICATION TRAINING
What Are Loops
 Loops allows the execution of a statement or a group of statement multiple times.
 In order to enter the loop there are certain conditions defined in the beginning.
 Once the condition becomes false the loop stops and the control moves out of the loop.
Start
Conditional Code
Condition
If condition
is false
If condition
is true
Exit
Loops FiniteInfinite
www.edureka.co/pythonEDUREKA PYTHON CERTIFICATION TRAINING
Loops In Python
www.edureka.co/pythonEDUREKA PYTHON CERTIFICATION TRAINING
While Loop
While loops are known as indefinite or conditional loops. They will keep iterating until certain
conditions are met. There is no guarantee ahead of time regarding how many times the loop will
iterate.
Syntax:
Start
While
Condition?
Body of the loop
True
False
Exit
While
For
Nested
www.edureka.co/pythonEDUREKA PYTHON CERTIFICATION TRAINING
While Loop Example
A little guessing game
Let the correct answer be 13
Input Number: 10 Number is too small
Input Number: 15 Number is too large
Input Number: 13 Exit: Congratulations. You made it!
While
For
Nested
www.edureka.co/pythonEDUREKA PYTHON CERTIFICATION TRAINING
For Loop
For loop is a Python loop which repeats a group of statements a specified number of times. The
for loop provides a syntax where the following information is provided:
 Boolean condition
 The initial value of the counting variable
 Incrementation of counting variable
Start
Execute Statement (s)
End
Next item from
sequence
If no more items in the
sequence
Item from
sequence
While
For
Nested
www.edureka.co/pythonEDUREKA PYTHON CERTIFICATION TRAINING
For Loop Example
 Lets find factorial
 Notice we know the number of iterations so for loop is a better option
3! = 3(2)(1)
4! = 4(3)(2)(1)
5! = 5(4)(3)(2)(1)
Example
Factorial = n(n-1)(n-2)…..1
n n-1 n-2 1
While
For
Nested
www.edureka.co/pythonEDUREKA PYTHON CERTIFICATION TRAINING
Nested Loops
Python programming language allows use of loop inside another
loop. This is called Nested Loop. below is the syntax for the same:
Syntax: Syntax:
While
For
Nested
www.edureka.co/pythonEDUREKA PYTHON CERTIFICATION TRAINING
Nested Loop Example
Lets code a program in Python that effectively simulates a bank ATM.
Enter the 4-digit pin
Make a withdrawal
Pay in
Check balance
Return card
While
For
Nested
www.edureka.co/pythonEDUREKA PYTHON CERTIFICATION TRAINING
Nested Loop Example
 Lets write a code to print the Pythagorean numbers.
 Three integers satisfying a2+b2=c2 are called Pythagorean numbers
c2a2
b2
3 4 5
5 12 13
6 8 10
8 15 17
9 12 15
12 16 20
Enter the maximum number:
20
Pythagorean numbers
between 1-20
While
For
Nested
www.edureka.co/pythonEDUREKA PYTHON CERTIFICATION TRAINING
Nested Loop Example
While
For
Nested
Bulk reservation:
Name:
Age:
Sex:
Using a for loop inside while loop
www.edureka.co/pythonEDUREKA PYTHON CERTIFICATION TRAINING
Agenda
Why loops What are loops
While loop For loop
Types of loops
Nested loop
www.edureka.co/pythonEDUREKA PYTHON CERTIFICATION TRAINING
Thank You …
Questions/Queries/Feedback

More Related Content

What's hot (20)

PDF
Class and Objects in Java
Spotle.ai
Ā 
PPTX
Data Structures in Python
Devashish Kumar
Ā 
PDF
Set methods in python
deepalishinkar1
Ā 
PDF
Python Variable Types, List, Tuple, Dictionary
Soba Arjun
Ā 
PPTX
Functions in python
colorsof
Ā 
PPTX
Python variables and data types.pptx
AkshayAggarwal79
Ā 
PPTX
Nested loops
Neeru Mittal
Ā 
PPTX
Polymorphism in Python
Home
Ā 
PDF
Arrays in python
moazamali28
Ā 
PDF
What is Python Lambda Function? Python Tutorial | Edureka
Edureka!
Ā 
PPTX
Object oriented programming in python
baabtra.com - No. 1 supplier of quality freshers
Ā 
PDF
Constructors and Destructors
Dr Sukhpal Singh Gill
Ā 
PPTX
classes and objects in C++
HalaiHansaika
Ā 
PDF
Python Programming Language | Python Classes | Python Tutorial | Python Train...
Edureka!
Ā 
PPTX
Python-Inheritance.pptx
Karudaiyar Ganapathy
Ā 
PPTX
Evaluation of postfix expression
Akhil Ahuja
Ā 
PPTX
Constructors and Destructor in C++
International Institute of Information Technology (I²IT)
Ā 
PDF
Python basic
Saifuddin Kaijar
Ā 
PPTX
Regular expressions in Python
Sujith Kumar
Ā 
Class and Objects in Java
Spotle.ai
Ā 
Data Structures in Python
Devashish Kumar
Ā 
Set methods in python
deepalishinkar1
Ā 
Python Variable Types, List, Tuple, Dictionary
Soba Arjun
Ā 
Functions in python
colorsof
Ā 
Python variables and data types.pptx
AkshayAggarwal79
Ā 
Nested loops
Neeru Mittal
Ā 
Polymorphism in Python
Home
Ā 
Arrays in python
moazamali28
Ā 
What is Python Lambda Function? Python Tutorial | Edureka
Edureka!
Ā 
Object oriented programming in python
baabtra.com - No. 1 supplier of quality freshers
Ā 
Constructors and Destructors
Dr Sukhpal Singh Gill
Ā 
classes and objects in C++
HalaiHansaika
Ā 
Python Programming Language | Python Classes | Python Tutorial | Python Train...
Edureka!
Ā 
Python-Inheritance.pptx
Karudaiyar Ganapathy
Ā 
Evaluation of postfix expression
Akhil Ahuja
Ā 
Python basic
Saifuddin Kaijar
Ā 
Regular expressions in Python
Sujith Kumar
Ā 

Similar to Python Loops Tutorial | Python For Loop | While Loop Python | Python Training | Edureka (20)

PPTX
Loops in Python.pptx
Guru Nanak Dev University, Amritsar
Ā 
PDF
2 Python Basics II meeting 2 tunghai university pdf
Anggi Andriyadi
Ā 
PPTX
python ppt.pptx
ssuserd10678
Ā 
PPTX
While loop
RabiyaZhexembayeva
Ā 
PPTX
Mastering Python lesson 3a
Ruth Marvin
Ā 
PPTX
Looping Statements and Control Statements in Python
PriyankaC44
Ā 
DOCX
iterations.docx
ssuser2e84e4
Ā 
PPTX
Python notes for students to learn and develop
kavithaadhilakshmi
Ā 
PDF
Python Decision Making And Loops.pdf
NehaSpillai1
Ā 
PPTX
Python programming workshop session 2
Abdul Haseeb
Ā 
PPTX
ForLoops.pptx
RabiyaZhexembayeva
Ā 
PPTX
loopin gstatement in python using .pptx
urvashipundir04
Ā 
PDF
loops python.pdf
MUHAMMED MASHAHIL PUKKUNNUMMAL
Ā 
PPTX
Loops in python including control statements and various test cases
AnuragSharma710741
Ā 
PPTX
Going loopy - Introduction to Loops.pptx
Amy Nightingale
Ā 
PPTX
Introduction To Programming with Python Lecture 2
Syed Farjad Zia Zaidi
Ā 
PPTX
Python Development Workshop DAY 06 QUEST
AttaMohammadPanhyar
Ā 
PDF
While-For-loop in python used in college
ssuser7a7cd61
Ā 
PPTX
While_for_loop presententationin first year students
SIHIGOPAL
Ā 
Loops in Python.pptx
Guru Nanak Dev University, Amritsar
Ā 
2 Python Basics II meeting 2 tunghai university pdf
Anggi Andriyadi
Ā 
python ppt.pptx
ssuserd10678
Ā 
While loop
RabiyaZhexembayeva
Ā 
Mastering Python lesson 3a
Ruth Marvin
Ā 
Looping Statements and Control Statements in Python
PriyankaC44
Ā 
iterations.docx
ssuser2e84e4
Ā 
Python notes for students to learn and develop
kavithaadhilakshmi
Ā 
Python Decision Making And Loops.pdf
NehaSpillai1
Ā 
Python programming workshop session 2
Abdul Haseeb
Ā 
ForLoops.pptx
RabiyaZhexembayeva
Ā 
loopin gstatement in python using .pptx
urvashipundir04
Ā 
loops python.pdf
MUHAMMED MASHAHIL PUKKUNNUMMAL
Ā 
Loops in python including control statements and various test cases
AnuragSharma710741
Ā 
Going loopy - Introduction to Loops.pptx
Amy Nightingale
Ā 
Introduction To Programming with Python Lecture 2
Syed Farjad Zia Zaidi
Ā 
Python Development Workshop DAY 06 QUEST
AttaMohammadPanhyar
Ā 
While-For-loop in python used in college
ssuser7a7cd61
Ā 
While_for_loop presententationin first year students
SIHIGOPAL
Ā 
Ad

More from Edureka! (20)

PDF
What to learn during the 21 days Lockdown | Edureka
Edureka!
Ā 
PDF
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
Ā 
PDF
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
Ā 
PDF
Tableau Tutorial for Data Science | Edureka
Edureka!
Ā 
PDF
Python Programming Tutorial | Edureka
Edureka!
Ā 
PDF
Top 5 PMP Certifications | Edureka
Edureka!
Ā 
PDF
Top Maven Interview Questions in 2020 | Edureka
Edureka!
Ā 
PDF
Linux Mint Tutorial | Edureka
Edureka!
Ā 
PDF
How to Deploy Java Web App in AWS| Edureka
Edureka!
Ā 
PDF
Importance of Digital Marketing | Edureka
Edureka!
Ā 
PDF
RPA in 2020 | Edureka
Edureka!
Ā 
PDF
Email Notifications in Jenkins | Edureka
Edureka!
Ā 
PDF
EA Algorithm in Machine Learning | Edureka
Edureka!
Ā 
PDF
Cognitive AI Tutorial | Edureka
Edureka!
Ā 
PDF
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
Ā 
PDF
Blue Prism Top Interview Questions | Edureka
Edureka!
Ā 
PDF
Big Data on AWS Tutorial | Edureka
Edureka!
Ā 
PDF
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
Ā 
PDF
Kubernetes Installation on Ubuntu | Edureka
Edureka!
Ā 
PDF
Introduction to DevOps | Edureka
Edureka!
Ā 
What to learn during the 21 days Lockdown | Edureka
Edureka!
Ā 
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
Ā 
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
Ā 
Tableau Tutorial for Data Science | Edureka
Edureka!
Ā 
Python Programming Tutorial | Edureka
Edureka!
Ā 
Top 5 PMP Certifications | Edureka
Edureka!
Ā 
Top Maven Interview Questions in 2020 | Edureka
Edureka!
Ā 
Linux Mint Tutorial | Edureka
Edureka!
Ā 
How to Deploy Java Web App in AWS| Edureka
Edureka!
Ā 
Importance of Digital Marketing | Edureka
Edureka!
Ā 
RPA in 2020 | Edureka
Edureka!
Ā 
Email Notifications in Jenkins | Edureka
Edureka!
Ā 
EA Algorithm in Machine Learning | Edureka
Edureka!
Ā 
Cognitive AI Tutorial | Edureka
Edureka!
Ā 
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
Ā 
Blue Prism Top Interview Questions | Edureka
Edureka!
Ā 
Big Data on AWS Tutorial | Edureka
Edureka!
Ā 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
Ā 
Kubernetes Installation on Ubuntu | Edureka
Edureka!
Ā 
Introduction to DevOps | Edureka
Edureka!
Ā 
Ad

Recently uploaded (20)

PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
Ā 
PDF
šŸš€ Let’s Build Our First Slack Workflow! šŸ”§.pdf
SanjeetMishra29
Ā 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
Ā 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
Ā 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
Ā 
PPTX
Securing Model Context Protocol with Keycloak: AuthN/AuthZ for MCP Servers
Hitachi, Ltd. OSS Solution Center.
Ā 
PDF
Kit-Works Team Study_20250627_ķ•œė‹¬ė§Œģ—ė§Œė“ ģ‚¬ė‚“ģ„œė¹„ģŠ¤ķ‚¤ė§(ģ–‘ė‹¤ģœ—).pdf
Wonjun Hwang
Ā 
PDF
Linux schedulers for fun and profit with SchedKit
Alessio Biancalana
Ā 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
Ā 
PDF
Evolution: How True AI is Redefining Safety in Industry 4.0
vikaassingh4433
Ā 
PDF
Modern Decentralized Application Architectures.pdf
Kalema Edgar
Ā 
PPTX
Manual Testing for Accessibility Enhancement
Julia Undeutsch
Ā 
PPTX
Digital Circuits, important subject in CS
contactparinay1
Ā 
PPTX
CapCut Pro PC Crack Latest Version Free Free
josanj305
Ā 
PPTX
Essential Content-centric Plugins for your Website
Laura Byrne
Ā 
PDF
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
Ā 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
Ā 
PPTX
Role_of_Artificial_Intelligence_in_Livestock_Extension_Services.pptx
DrRajdeepMadavi
Ā 
PPTX
Talbott's brief History of Computers for CollabDays Hamburg 2025
Talbott Crowell
Ā 
PDF
ā€œComputer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,ā€ a ...
Edge AI and Vision Alliance
Ā 
The Project Compass - GDG on Campus MSIT
dscmsitkol
Ā 
šŸš€ Let’s Build Our First Slack Workflow! šŸ”§.pdf
SanjeetMishra29
Ā 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
Ā 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
Ā 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
Ā 
Securing Model Context Protocol with Keycloak: AuthN/AuthZ for MCP Servers
Hitachi, Ltd. OSS Solution Center.
Ā 
Kit-Works Team Study_20250627_ķ•œė‹¬ė§Œģ—ė§Œė“ ģ‚¬ė‚“ģ„œė¹„ģŠ¤ķ‚¤ė§(ģ–‘ė‹¤ģœ—).pdf
Wonjun Hwang
Ā 
Linux schedulers for fun and profit with SchedKit
Alessio Biancalana
Ā 
How do you fast track Agentic automation use cases discovery?
DianaGray10
Ā 
Evolution: How True AI is Redefining Safety in Industry 4.0
vikaassingh4433
Ā 
Modern Decentralized Application Architectures.pdf
Kalema Edgar
Ā 
Manual Testing for Accessibility Enhancement
Julia Undeutsch
Ā 
Digital Circuits, important subject in CS
contactparinay1
Ā 
CapCut Pro PC Crack Latest Version Free Free
josanj305
Ā 
Essential Content-centric Plugins for your Website
Laura Byrne
Ā 
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
Ā 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
Ā 
Role_of_Artificial_Intelligence_in_Livestock_Extension_Services.pptx
DrRajdeepMadavi
Ā 
Talbott's brief History of Computers for CollabDays Hamburg 2025
Talbott Crowell
Ā 
ā€œComputer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,ā€ a ...
Edge AI and Vision Alliance
Ā 

Python Loops Tutorial | Python For Loop | While Loop Python | Python Training | Edureka