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
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
