Can we use break statement in a Python if clause?


Python's break keyword is used as decision control statement. It causes the remaining iterations to be abandoned and control of execution goes to next statement after the end of loop. Invariably it is executed conditionally and appears inside if block within a loop.

while expr==True:
    stmt1    
    stmt2    
    if expr2==True:
       break
    stmt3
    stmt4

   However it can't be used in an if block if it is not a part of loop. 

Updated on: 26-Feb-2020

115 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements