Break, Continue and Pass in Python

Break and Continue are mainly used to control loops. Manytime we need to skip any specific iteration or end loop when some specific condition arises, here we use break and continue.
Jump to specific section:
  1. Break
  2. Continue
  3. pass

Break

Break keyword is used to break loops when any specific condition arises.
Example:

for i in range(10):
print(i)
if (i==5):
    print("Break loop if i = 5")
    break
    
Output:
0
1
2
3
4
5
Break loop if i = 5 

Continue

Continue keyword is used to skip some iterations based on conditions.
Example:

for i in range(10):
    if (i==5):
        print("When i = 5, code below continue will not execute for current iteration")
        continue
    print(i)
    
Output:
0
1
2
3
4
When i = 5, code below continue will not execute for current iteration
6
7
8
9

Pass

In python we can not leave any block empty. If we need to leave any block empty then we use 'pass' keyword.
Let us see what will happend if we leave block empty.

for i in range(10):
    # this block is left empty, this line 
    # is not considered as code 
    # because this is comment
Output:
File "", line 4
# because this is comment
^
IndentationError: expected an indented block after 'for' statement on line 1
Now we will use pass keyword

for i in range(10):
    # this block is left empty, this line 
    # is not considered as code 
    # because this is comment
    pass
Output:

Output is empty and no any error arise.