What is break,continue and pass in Python?

 "break", "continue", and "pass" are keywords in Python that are used in loops to control the flow of the loop.

1. Break: The "break" keyword is used to exit a loop early before it reaches the end of its iteration. When the "break" statement is encountered, the loop is terminated immediately, and control is passed to the next statement after the loop.

Example:

for i in range(10): if i == 5: break print(i)

Output: 0 1 2 3 4

  1. Continue: The "continue" keyword is used to skip the current iteration of a loop and move on to the next iteration. When the "continue" statement is encountered, the current iteration is skipped, and control is passed to the next iteration of the loop.

Example:

for i in range(10): if i == 5: continue print(i)

Output: 0 1 2 3 4 6 7 8 9

  1. Pass: The "pass" keyword is used as a placeholder in the code when you need to include a statement that doesn't do anything. The "pass" statement is a no-op, and its purpose is to act as a placeholder where you need to include a statement, but you don't have anything to put in it yet.
Example:

def func():
pass
The "pass" keyword is often used in the place of an empty loop or an empty function definition to indicate that code will be added later.

Comments