Advertisements
Advertisements
Question
Explain the difference between break and continue statements in Python with a suitable example.
Distinguish Between
Explain
Advertisements
Solution
Break exits the loop entirely, while continue skips the current iteration and moves to the next one.
Example of break:
for i in range(5):
if i == 2:
break # Exits the loop
print(i)
Output:
1
Example of continue:
for i in range(5):
if i == 2:
continue # Skips printing 2
print
Output:
1
3
4
5shaalaa.com
Is there an error in this question or solution?
