Python Branching
Break , Continue, Pass are python branching techniques.
Break:
Break statement terminates the loop containing it.
# break statement
for val in [1,2,3,4,5]:
if val == 3:
break
print(val)
print("The end")
O/p:
1
2
The end
Continue Skips current iteration.
# break statement
for val in [1,2,3,4,5]:
if val == 3:
continue
print(val)
print("The end")
O/p:
1
2
4
5
The end
Pass:
To pass without executing code.
for val in [1,2,3,4,5]:
if val == 3:
pass
print ('this is pass block')
print(val)
print("The end")
Op:
1
2
this is pass block
3
4
5
The end
No comments:
Post a Comment