In Python, break
is used to exit a loop immediately, and continue
is used to skip the current iteration and continue with the next one.
Python में break
का उपयोग loop को तुरंत बंद करने के लिए होता है और continue
का उपयोग current iteration को छोड़ने और अगले पर जाने के लिए किया जाता है।
for i in range(1, 6):
if i == 3:
break
print(i)
Output:
1 2
i = 1
while i <= 5:
if i == 4:
break
print(i)
i += 1
Output:
1 2 3
for i in range(1, 6):
if i == 3:
continue
print(i)
Output:
1 2 4 5
i = 0
while i < 5:
i += 1
if i == 3:
continue
print(i)
Output:
1 2 4 5
for i in range(1, 10):
if i == 5:
continue
if i == 8:
break
print(i)
Output:
1 2 3 4 6 7