26. difference between Break and Continue statements with an example python program?
# The continue statement starts the next pass of the loop
# bypassing the rest of the loop.
print("loop with continue statement: ")
for i in (1,2,3,4,5):
if i == 3:
#if i=3 then go to the next iteration
continue
print(i)
#The break statement terminates the loop early.
print("loop with break statement: ")
for i in (1,2,3,4,5):
if i == 3:
#if i = 3 then stop the loop
break
print(i)
Comments
Leave a comment