0% found this document useful (0 votes)
32 views14 pages

Break Cotinue

Uploaded by

Adarsh Sah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views14 pages

Break Cotinue

Uploaded by

Adarsh Sah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Loop Control Statements

Break and Continue


Break
• 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.
Flow chart of break statement
The break Statement
• The keyword break allows the programmer to terminate the loop.
• When the break statement is encountered inside a loop, the loop is
immediately terminated.
Working of break in while and for loop

• while test-Boolean-expression:

body of while

if condition:

break

body of while

Statement(s)
Working of break in while loop

for var in sequence:


body of for
if condition:
break
body of for
statement(s)
Working of break in for loop
Example 1

for letter in “Python”:


if letter == 'h':
break
print (“Current Letter :”, letter)
Example 2

var = 10
while var > 0:
print (“Current variable value :”, var)
var = var -1
if var == 5:
break
print "Good bye!"
Continue statement

• Causes the loop to skip the remainder of its body and


immediately retest its condition prior to reiterating.
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.
Flow Diagram
Working of continue in while and for loop

• while test-Boolean-expression:

body of while

if condition:

continue

body of while

Statement(s)
Working of continue in while loop

for var in sequence:


body of for
if condition:
continue
body of for
statement(s) Working of continue in for loop
Example1

for letter in “Python”:


if letter == 'h':
continue
print (“Current Letter :”, letter)
Example 2

var = 10
while var > 0:
var = var -1
if var == 5:
continue
print ('Current variable value :', var )
print ("Good bye!“)
Conclusion

• The break statement is used to terminate from


the loop.
• Where as continue statement is used to skip the
current iteration and continues with the next
iteration.

You might also like