Advertisements
Advertisements
प्रश्न
Explain the difference between break and continue statements in Python with a suitable example.
अंतर स्पष्ट करें
स्पष्ट कीजिए
Advertisements
उत्तर
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
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
