, asked
Views : 5

Can we use break statement in a Python if clause?

Can we use break statement in a Python if clause?                                             

1 Answer
Malhar Lathkar

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. 

Advertisements
Related Questions