Python Break, Continue, and Pass Statements

In programming, Interrupt is a process that allows changing execution of the current flow. The interrupt could exit the process, and skip the line of the code block. Break, Continue, and Pass are the interrupt keywords that are used in Python programming. Let’s see those


Objectives

  • Python Break statement

  • Python Continue statement

  • Python Pass statement


Python Break statement

Below program will print 1 to 5, after that it will exit, because we used break keyword when the loop printing 5.

Code

# Break
for number in range(1, 11, 1):
    print(number)
    if number == 5:
        break

Output

1
2
3
4
5

Process finished with exit code 0


Python Continue statement

Below program will print only the even number, because when the odd number will come, it is checking the condition and interrupt the program, with continue keyword

Code

# Continue
for number in range(1, 11, 1):
    if (number % 2) != 0:
        continue
    print(number)

Output

2
4
6
8
10

Process finished with exit code 0


Python Pass statement

The pass statement is used as a placeholder for future code and avoid definition missing error

# Pass
for number in range(1, 11, 1):
    pass


Python Break, Continue, and Pass video tutorial