SlideShare a Scribd company logo
Prof. Neeraj Bhargava
Vishal Dutt
Department of Computer Science, School of
Engineering & System Sciences
MDS University, Ajmer
break statement
• It terminates the current loop and resumes
execution at the next statement, just like the
traditional break statement in C.
• The most common use for break is when some
external condition is triggered requiring a hasty
exit from a loop. The break statement can be used
in both while and for loops.
• If you are using nested loops, the break statement
stops the execution of the innermost loop and start
executing the next line of code after the block.
Syntax
break
Example
for letter in 'Python': # First Example
if letter == 'h':
break
print 'Current Letter :', letter
var = 10 # Second Example
while var > 0:
print 'Current variable value :', var
var = var -1
if var == 5:
break
print "Good bye!"
Output
Current Letter : P
Current Letter : y
Current Letter : t
Current variable value : 10
Current variable value : 9
Current variable value : 8
Current variable value : 7
Current variable value : 6
Good bye!
continue statement
 It returns the control to the beginning of the while
loop.. The continue statement rejects all the
remaining statements in the current iteration of the
loop and moves the control back to the top of the loop.
 The continue statement can be used in
both while and for loops.
Syntax
continue
Example
for letter in 'Python': # First Example
if letter == 'h':
continue
print 'Current Letter :', letter
var = 10 # Second Example
while var > 0:
var = var -1
if var == 5:
continue
print 'Current variable value :', var
print "Good bye!"
Output
Current Letter : P
Current Letter : y
Current Letter : t
Current Letter : o
Current Letter : n
Current variable value : 9
Current variable value : 8
Current variable value : 7
Current variable value : 6
Current variable value : 4
Current variable value : 3
Current variable value : 2
Current variable value : 1
Current variable value : 0
Good bye!
pass Statement
 It is used when a statement is required syntactically
but you do not want any command or code to execute.
 The pass statement is a null operation; nothing
happens when it executes. The pass is also useful in
places where your code will eventually go, but has not
been written yet (e.g., in stubs for example) −
Syntax
pass
Example
for letter in 'Python':
if letter == 'h':
pass
print 'This is pass block'
print 'Current Letter :', letter
print "Good bye!"
#Output
Current Letter : P
Current Letter : y
Current Letter : t
This is pass block
Current Letter : h
Current Letter : o
Current Letter : n
Good bye!
Questions
 Explain break statement with example?
 Explain continue statement with example?
 Explain pass statement with example?

More Related Content

PPTX
Python session3
PDF
PPTX
Banner Grabbing
PPTX
Looping and Switchcase BDCR
PPT
C++loop statements
PPTX
Loops in C Programming Language
PPTX
Break,Pass and Continue.pptx
PPTX
This is all about control flow in python intruducing the Break and Continue.pptx
Python session3
Banner Grabbing
Looping and Switchcase BDCR
C++loop statements
Loops in C Programming Language
Break,Pass and Continue.pptx
This is all about control flow in python intruducing the Break and Continue.pptx

Similar to Python decision making_loops_control statements part8 (20)

PPTX
break continue and pass in python progran.pptx
PPTX
a1 this is in python that has break continue and pass.pptx
PDF
Break, Continue and Pass in Python.pdf
PPTX
break continue and pass statement in python.pptx
PPTX
6 Iterative Statements.pptx
PDF
python program
PPTX
Jump statment in python
PPTX
Loop control structure
PDF
PYTHON FULL TUTORIAL WITH PROGRAMMS
PPTX
Python Flow Control
PPT
Python session3
PPTX
industry coding practice unit-2 ppt.pptx
PDF
E-Notes_3721_Content_Document_20250107032537PM.pdf
PPTX
While_for_loop presententationin first year students
PDF
While-For-loop in python used in college
PPTX
MATLAB Programming - Loop Control Part 2
PPTX
control statements in python.pptx
PPTX
TN 12 computer Science - ppt CHAPTER-6.pptx
PPTX
UNIT – 3.pptx for first year engineering
DOCX
Python unit 3 and Unit 4
break continue and pass in python progran.pptx
a1 this is in python that has break continue and pass.pptx
Break, Continue and Pass in Python.pdf
break continue and pass statement in python.pptx
6 Iterative Statements.pptx
python program
Jump statment in python
Loop control structure
PYTHON FULL TUTORIAL WITH PROGRAMMS
Python Flow Control
Python session3
industry coding practice unit-2 ppt.pptx
E-Notes_3721_Content_Document_20250107032537PM.pdf
While_for_loop presententationin first year students
While-For-loop in python used in college
MATLAB Programming - Loop Control Part 2
control statements in python.pptx
TN 12 computer Science - ppt CHAPTER-6.pptx
UNIT – 3.pptx for first year engineering
Python unit 3 and Unit 4
Ad

More from Vishal Dutt (20)

PPTX
Grid computing components
PPTX
Python files / directories part16
PPTX
Python Classes and Objects part14
PPTX
Python Classes and Objects part13
PPTX
Python files / directories part15
PPTX
Python functions part12
PPTX
Python functions part11
PPTX
Python functions part10
PPTX
List view5
PPTX
Python decision making_loops_control statements part9
PPTX
List view4
PPTX
List view3
PPTX
Python decision making_loops part7
PPTX
Python decision making_loops part6
PPTX
List view2
PPTX
List view1
PPTX
Python decision making part5
PPTX
Python decision making part4
PPTX
Python operators part3
PPTX
Python operators part2
Grid computing components
Python files / directories part16
Python Classes and Objects part14
Python Classes and Objects part13
Python files / directories part15
Python functions part12
Python functions part11
Python functions part10
List view5
Python decision making_loops_control statements part9
List view4
List view3
Python decision making_loops part7
Python decision making_loops part6
List view2
List view1
Python decision making part5
Python decision making part4
Python operators part3
Python operators part2
Ad

Recently uploaded (20)

PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
Insiders guide to clinical Medicine.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Pre independence Education in Inndia.pdf
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Sports Quiz easy sports quiz sports quiz
PPTX
Lesson notes of climatology university.
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
master seminar digital applications in india
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
STATICS OF THE RIGID BODIES Hibbelers.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
RMMM.pdf make it easy to upload and study
Insiders guide to clinical Medicine.pdf
Microbial disease of the cardiovascular and lymphatic systems
Pre independence Education in Inndia.pdf
01-Introduction-to-Information-Management.pdf
Cell Structure & Organelles in detailed.
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Sports Quiz easy sports quiz sports quiz
Lesson notes of climatology university.
Anesthesia in Laparoscopic Surgery in India
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
master seminar digital applications in india
Supply Chain Operations Speaking Notes -ICLT Program
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPH.pptx obstetrics and gynecology in nursing
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...

Python decision making_loops_control statements part8

  • 1. Prof. Neeraj Bhargava Vishal Dutt Department of Computer Science, School of Engineering & System Sciences MDS University, Ajmer
  • 2. break statement • It terminates the current loop and resumes execution at the next statement, just like the traditional break statement in C. • The most common use for break is when some external condition is triggered requiring a hasty exit from a loop. The break statement can be used in both while and for loops. • If you are using nested loops, the break statement stops the execution of the innermost loop and start executing the next line of code after the block.
  • 4. Example for letter in 'Python': # First Example if letter == 'h': break print 'Current Letter :', letter var = 10 # Second Example while var > 0: print 'Current variable value :', var var = var -1 if var == 5: break print "Good bye!"
  • 5. Output Current Letter : P Current Letter : y Current Letter : t Current variable value : 10 Current variable value : 9 Current variable value : 8 Current variable value : 7 Current variable value : 6 Good bye!
  • 6. continue statement  It returns the control to the beginning of the while loop.. The continue statement rejects all the remaining statements in the current iteration of the loop and moves the control back to the top of the loop.  The continue statement can be used in both while and for loops.
  • 8. Example for letter in 'Python': # First Example if letter == 'h': continue print 'Current Letter :', letter var = 10 # Second Example while var > 0: var = var -1 if var == 5: continue print 'Current variable value :', var print "Good bye!"
  • 9. Output Current Letter : P Current Letter : y Current Letter : t Current Letter : o Current Letter : n Current variable value : 9 Current variable value : 8 Current variable value : 7 Current variable value : 6 Current variable value : 4 Current variable value : 3 Current variable value : 2 Current variable value : 1 Current variable value : 0 Good bye!
  • 10. pass Statement  It is used when a statement is required syntactically but you do not want any command or code to execute.  The pass statement is a null operation; nothing happens when it executes. The pass is also useful in places where your code will eventually go, but has not been written yet (e.g., in stubs for example) − Syntax pass
  • 11. Example for letter in 'Python': if letter == 'h': pass print 'This is pass block' print 'Current Letter :', letter print "Good bye!" #Output Current Letter : P Current Letter : y Current Letter : t This is pass block Current Letter : h Current Letter : o Current Letter : n Good bye!
  • 12. Questions  Explain break statement with example?  Explain continue statement with example?  Explain pass statement with example?