English

Explain the difference between break and continue statements in Python with a suitable example. - Computer Science (Python)

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
5
shaalaa.com
  Is there an error in this question or solution?
2025-2026 (March) Board Sample Paper
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×