Conditional statements with break and continue in Python

In this tutorial, we will learn about the use and working of break and continue keywords with conditional statements in Python with the help of examples. By Abhishek Jain Last updated : December 18, 2023

Python break and continue keywords/statements

In Python, the break and continue are the keywords in Python, they are used for the different purposes inside the loop statements with the conditional statements. The break statement terminates the execution of the loop (if the given condition is true) whereas the continue statement skips the current execution of the loop (if the given condition is true) and jumps the execution to the next iteration.

1. Python break statement

The break can be used to unconditionally jump out of the loop. It terminates the execution of the loop. The break can be used in while loop and for loop. It is mostly required, when because of some external condition, we need to exit from a loop.

Example of Python break statement

for letter in "Python":
  if letter =='h':
     break
  print (letter)

Output

P
y
t

2. Python continue statement

The continue statement is used to tell Python to skip the rest of the statements of the current loop block and to move to next iteration, of the loop. The continue will return back the control to the beginning of the loop. This can also be used with both while and for statements.

Example of Python continue statement

for letter in "Python":
   if letter == 'h':
       continue
   print(letter)

Output

P
y
t
o
n

Python Tutorial

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.