SlideShare a Scribd company logo
Prof. Neeraj Bhargava
Vishal Dutt
Department of Computer Science, School of
Engineering & System Sciences
MDS University, Ajmer
Iterating by Sequence Index
• An alternative way of iterating through each item is
by index offset into the sequence itself.
Example
fruits = ['banana', 'apple', 'mango']
for index in range(len(fruits)):
print 'Current fruit :', fruits[index]
print "Good bye!"
#Output
Current fruit : banana
Current fruit : apple
Current fruit : mango
Good bye!
nested loops
• Python programming language allows to
use one loop inside another loop.
Syntax
for iterating_var in sequence:
for iterating_var in sequence:
statements(s)
statements(s)
nested while loop
Syntax
while expression:
while expression:
statement(s)
statement(s)
A final note on loop nesting is that you can put
any type of loop inside of any other type of
loop. For example a for loop can be inside a
while loop or vice versa.
Example
i = 2
while(i < 100):
j = 2
while(j <= (i/j)):
if not(i%j): break
j = j + 1
if (j > i/j) : print i, " is prime"
i = i + 1
print "Good bye!"
#Output
2 is prime
3 is prime
5 is prime
7 is prime
11 is prime
13 is prime
17 is prime
19 is prime
23 is prime
29 is prime
31 is prime
37 is prime
41 is prime
43 is prime
47 is prime
53 is prime
59 is prime
61 is prime
67 is prime
71 is prime
73 is prime
79 is prime
83 is prime
89 is prime
97 is prime
Good bye!
Loop Control Statements
 Loop control statements change execution from its
normal sequence. When execution leaves a scope, all
automatic objects that were created in that scope are
destroyed.
 Python supports the following control statements.
Click the following links to check their detail.
Sr.No. Control Statement & Description
1 break statement: Terminates the loop statement and
transfers execution to the statement immediately
following the loop.
2 continue statement: Causes the loop to skip the
remainder of its body and immediately retest its
condition prior to reiterating.
3 pass statement: The pass statement in Python is used
when a statement is required syntactically but you do
not want any command or code to execute.
Questions
 Explain various Loop statement?
 Explain nested Loop with example?

More Related Content

What's hot

Java control flow statements
Java control flow statementsJava control flow statements
Java control flow statements
Future Programming
 
Control flow statements in java
Control flow statements in javaControl flow statements in java
Control flow statements in java
yugandhar vadlamudi
 
M C6java5
M C6java5M C6java5
M C6java5
mbruggen
 
Control structures ii
Control structures ii Control structures ii
Control structures ii
Ahmad Idrees
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
Madishetty Prathibha
 
Presentation on Template Method Design Pattern
Presentation on Template Method Design PatternPresentation on Template Method Design Pattern
Presentation on Template Method Design Pattern
Asif Tayef
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision Control
Jayfee Ramos
 
Data structures vb
Data structures vbData structures vb
Data structures vb
nicky_walters
 
03 conditions loops
03   conditions loops03   conditions loops
03 conditions loops
Manzoor ALam
 
งานย อยท _6
งานย อยท _6งานย อยท _6
งานย อยท _6
Little Junney
 
Lecture15 comparisonoftheloopcontrolstructures.ppt
Lecture15 comparisonoftheloopcontrolstructures.pptLecture15 comparisonoftheloopcontrolstructures.ppt
Lecture15 comparisonoftheloopcontrolstructures.ppt
eShikshak
 
Decision making and looping
Decision making and loopingDecision making and looping
Decision making and looping
Hossain Md Shakhawat
 
Control structures i
Control structures i Control structures i
Control structures i
Ahmad Idrees
 
Java loops for, while and do...while
Java loops   for, while and do...whileJava loops   for, while and do...while
Java loops for, while and do...while
Jayfee Ramos
 
control statements
control statementscontrol statements
control statements
Azeem Sultan
 
Looping and Switchcase BDCR
Looping and Switchcase BDCRLooping and Switchcase BDCR
Looping and Switchcase BDCR
beriver
 
Program control statements in c#
Program control statements in c#Program control statements in c#
Program control statements in c#
Dr.Neeraj Kumar Pandey
 
Control statements
Control statementsControl statements
Control statements
Kanwalpreet Kaur
 
Programming in python - Week 4
Programming in python  - Week 4Programming in python  - Week 4
Programming in python - Week 4
Priya Nayak
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
Mahantesh Devoor
 

What's hot (20)

Java control flow statements
Java control flow statementsJava control flow statements
Java control flow statements
 
Control flow statements in java
Control flow statements in javaControl flow statements in java
Control flow statements in java
 
M C6java5
M C6java5M C6java5
M C6java5
 
Control structures ii
Control structures ii Control structures ii
Control structures ii
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
 
Presentation on Template Method Design Pattern
Presentation on Template Method Design PatternPresentation on Template Method Design Pattern
Presentation on Template Method Design Pattern
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision Control
 
Data structures vb
Data structures vbData structures vb
Data structures vb
 
03 conditions loops
03   conditions loops03   conditions loops
03 conditions loops
 
งานย อยท _6
งานย อยท _6งานย อยท _6
งานย อยท _6
 
Lecture15 comparisonoftheloopcontrolstructures.ppt
Lecture15 comparisonoftheloopcontrolstructures.pptLecture15 comparisonoftheloopcontrolstructures.ppt
Lecture15 comparisonoftheloopcontrolstructures.ppt
 
Decision making and looping
Decision making and loopingDecision making and looping
Decision making and looping
 
Control structures i
Control structures i Control structures i
Control structures i
 
Java loops for, while and do...while
Java loops   for, while and do...whileJava loops   for, while and do...while
Java loops for, while and do...while
 
control statements
control statementscontrol statements
control statements
 
Looping and Switchcase BDCR
Looping and Switchcase BDCRLooping and Switchcase BDCR
Looping and Switchcase BDCR
 
Program control statements in c#
Program control statements in c#Program control statements in c#
Program control statements in c#
 
Control statements
Control statementsControl statements
Control statements
 
Programming in python - Week 4
Programming in python  - Week 4Programming in python  - Week 4
Programming in python - Week 4
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
 

Similar to Python decision making_loops part7

Loops in Python.pptx
Loops in Python.pptxLoops in Python.pptx
22H51A6755.pptx
22H51A6755.pptx22H51A6755.pptx
22H51A6755.pptx
Parameshwar Maddela
 
Slide 6_Control Structures.pdf
Slide 6_Control Structures.pdfSlide 6_Control Structures.pdf
Slide 6_Control Structures.pdf
NuthalapatiSasidhar
 
PM1
PM1PM1
PM1
ra na
 
Parallel Programming
Parallel ProgrammingParallel Programming
Parallel Programming
Roman Okolovich
 
Loops
LoopsLoops
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
Niket Chandrawanshi
 
prt123.pptx
prt123.pptxprt123.pptx
prt123.pptx
ASADKS
 
While-For-loop in python used in college
While-For-loop in python used in collegeWhile-For-loop in python used in college
While-For-loop in python used in college
ssuser7a7cd61
 
While_for_loop presententationin first year students
While_for_loop presententationin first year studentsWhile_for_loop presententationin first year students
While_for_loop presententationin first year students
SIHIGOPAL
 
Chapter 12 Computer Science ( ICS 12).pdf
Chapter 12 Computer Science ( ICS 12).pdfChapter 12 Computer Science ( ICS 12).pdf
Chapter 12 Computer Science ( ICS 12).pdf
AamirShahzad527024
 
Android Application Development - Level 3
Android Application Development - Level 3Android Application Development - Level 3
Android Application Development - Level 3
Isham Rashik
 
C language (Part 2)
C language (Part 2)C language (Part 2)
C language (Part 2)
SURBHI SAROHA
 
8 statement-level control structure
8 statement-level control structure8 statement-level control structure
8 statement-level control structure
jigeno
 
Control statements
Control statementsControl statements
Control statements
CutyChhaya
 
Loop control structure
Loop control structureLoop control structure
Loop control structure
narmadhakin
 
Session 3
Session 3Session 3
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming language
Vasavi College of Engg
 
Computer programming 2 Lesson 8
Computer programming 2  Lesson 8Computer programming 2  Lesson 8
Computer programming 2 Lesson 8
MLG College of Learning, Inc
 
2nd year computer science chapter 12 notes
2nd year computer science chapter 12 notes2nd year computer science chapter 12 notes
2nd year computer science chapter 12 notes
muhammadFaheem656405
 

Similar to Python decision making_loops part7 (20)

Loops in Python.pptx
Loops in Python.pptxLoops in Python.pptx
Loops in Python.pptx
 
22H51A6755.pptx
22H51A6755.pptx22H51A6755.pptx
22H51A6755.pptx
 
Slide 6_Control Structures.pdf
Slide 6_Control Structures.pdfSlide 6_Control Structures.pdf
Slide 6_Control Structures.pdf
 
PM1
PM1PM1
PM1
 
Parallel Programming
Parallel ProgrammingParallel Programming
Parallel Programming
 
Loops
LoopsLoops
Loops
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 
prt123.pptx
prt123.pptxprt123.pptx
prt123.pptx
 
While-For-loop in python used in college
While-For-loop in python used in collegeWhile-For-loop in python used in college
While-For-loop in python used in college
 
While_for_loop presententationin first year students
While_for_loop presententationin first year studentsWhile_for_loop presententationin first year students
While_for_loop presententationin first year students
 
Chapter 12 Computer Science ( ICS 12).pdf
Chapter 12 Computer Science ( ICS 12).pdfChapter 12 Computer Science ( ICS 12).pdf
Chapter 12 Computer Science ( ICS 12).pdf
 
Android Application Development - Level 3
Android Application Development - Level 3Android Application Development - Level 3
Android Application Development - Level 3
 
C language (Part 2)
C language (Part 2)C language (Part 2)
C language (Part 2)
 
8 statement-level control structure
8 statement-level control structure8 statement-level control structure
8 statement-level control structure
 
Control statements
Control statementsControl statements
Control statements
 
Loop control structure
Loop control structureLoop control structure
Loop control structure
 
Session 3
Session 3Session 3
Session 3
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming language
 
Computer programming 2 Lesson 8
Computer programming 2  Lesson 8Computer programming 2  Lesson 8
Computer programming 2 Lesson 8
 
2nd year computer science chapter 12 notes
2nd year computer science chapter 12 notes2nd year computer science chapter 12 notes
2nd year computer science chapter 12 notes
 

More from Vishal Dutt

Grid computing components
Grid computing componentsGrid computing components
Grid computing components
Vishal Dutt
 
Python files / directories part16
Python files / directories  part16Python files / directories  part16
Python files / directories part16
Vishal Dutt
 
Python Classes and Objects part14
Python Classes and Objects  part14Python Classes and Objects  part14
Python Classes and Objects part14
Vishal Dutt
 
Python Classes and Objects part13
Python Classes and Objects  part13Python Classes and Objects  part13
Python Classes and Objects part13
Vishal Dutt
 
Python files / directories part15
Python files / directories  part15Python files / directories  part15
Python files / directories part15
Vishal Dutt
 
Python functions part12
Python functions  part12Python functions  part12
Python functions part12
Vishal Dutt
 
Python functions part11
Python functions  part11Python functions  part11
Python functions part11
Vishal Dutt
 
Python functions part10
Python functions  part10Python functions  part10
Python functions part10
Vishal Dutt
 
List view5
List view5List view5
List view5
Vishal Dutt
 
Python decision making_loops_control statements part9
Python decision making_loops_control statements part9Python decision making_loops_control statements part9
Python decision making_loops_control statements part9
Vishal Dutt
 
List view4
List view4List view4
List view4
Vishal Dutt
 
List view3
List view3List view3
List view3
Vishal Dutt
 
Python decision making_loops_control statements part8
Python decision making_loops_control statements part8Python decision making_loops_control statements part8
Python decision making_loops_control statements part8
Vishal Dutt
 
Python decision making_loops part6
Python decision making_loops part6Python decision making_loops part6
Python decision making_loops part6
Vishal Dutt
 
List view2
List view2List view2
List view2
Vishal Dutt
 
List view1
List view1List view1
List view1
Vishal Dutt
 
Python decision making part5
Python decision making part5Python decision making part5
Python decision making part5
Vishal Dutt
 
Python decision making part4
Python decision making part4Python decision making part4
Python decision making part4
Vishal Dutt
 
Python operators part3
Python operators part3Python operators part3
Python operators part3
Vishal Dutt
 
Python operators part2
Python operators part2Python operators part2
Python operators part2
Vishal Dutt
 

More from Vishal Dutt (20)

Grid computing components
Grid computing componentsGrid computing components
Grid computing components
 
Python files / directories part16
Python files / directories  part16Python files / directories  part16
Python files / directories part16
 
Python Classes and Objects part14
Python Classes and Objects  part14Python Classes and Objects  part14
Python Classes and Objects part14
 
Python Classes and Objects part13
Python Classes and Objects  part13Python Classes and Objects  part13
Python Classes and Objects part13
 
Python files / directories part15
Python files / directories  part15Python files / directories  part15
Python files / directories part15
 
Python functions part12
Python functions  part12Python functions  part12
Python functions part12
 
Python functions part11
Python functions  part11Python functions  part11
Python functions part11
 
Python functions part10
Python functions  part10Python functions  part10
Python functions part10
 
List view5
List view5List view5
List view5
 
Python decision making_loops_control statements part9
Python decision making_loops_control statements part9Python decision making_loops_control statements part9
Python decision making_loops_control statements part9
 
List view4
List view4List view4
List view4
 
List view3
List view3List view3
List view3
 
Python decision making_loops_control statements part8
Python decision making_loops_control statements part8Python decision making_loops_control statements part8
Python decision making_loops_control statements part8
 
Python decision making_loops part6
Python decision making_loops part6Python decision making_loops part6
Python decision making_loops part6
 
List view2
List view2List view2
List view2
 
List view1
List view1List view1
List view1
 
Python decision making part5
Python decision making part5Python decision making part5
Python decision making part5
 
Python decision making part4
Python decision making part4Python decision making part4
Python decision making part4
 
Python operators part3
Python operators part3Python operators part3
Python operators part3
 
Python operators part2
Python operators part2Python operators part2
Python operators part2
 

Recently uploaded

A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 

Recently uploaded (20)

A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
 

Python decision making_loops part7

  • 1. Prof. Neeraj Bhargava Vishal Dutt Department of Computer Science, School of Engineering & System Sciences MDS University, Ajmer
  • 2. Iterating by Sequence Index • An alternative way of iterating through each item is by index offset into the sequence itself. Example fruits = ['banana', 'apple', 'mango'] for index in range(len(fruits)): print 'Current fruit :', fruits[index] print "Good bye!" #Output Current fruit : banana Current fruit : apple Current fruit : mango Good bye!
  • 3. nested loops • Python programming language allows to use one loop inside another loop. Syntax for iterating_var in sequence: for iterating_var in sequence: statements(s) statements(s)
  • 4. nested while loop Syntax while expression: while expression: statement(s) statement(s) A final note on loop nesting is that you can put any type of loop inside of any other type of loop. For example a for loop can be inside a while loop or vice versa.
  • 5. Example i = 2 while(i < 100): j = 2 while(j <= (i/j)): if not(i%j): break j = j + 1 if (j > i/j) : print i, " is prime" i = i + 1 print "Good bye!" #Output 2 is prime 3 is prime 5 is prime 7 is prime 11 is prime 13 is prime 17 is prime 19 is prime 23 is prime 29 is prime 31 is prime 37 is prime 41 is prime 43 is prime 47 is prime 53 is prime 59 is prime 61 is prime 67 is prime 71 is prime 73 is prime 79 is prime 83 is prime 89 is prime 97 is prime Good bye!
  • 6. Loop Control Statements  Loop control statements change execution from its normal sequence. When execution leaves a scope, all automatic objects that were created in that scope are destroyed.  Python supports the following control statements. Click the following links to check their detail.
  • 7. Sr.No. Control Statement & Description 1 break statement: Terminates the loop statement and transfers execution to the statement immediately following the loop. 2 continue statement: Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating. 3 pass statement: The pass statement in Python is used when a statement is required syntactically but you do not want any command or code to execute.
  • 8. Questions  Explain various Loop statement?  Explain nested Loop with example?