Can we use break statement in a Python if clause?

PythonServer Side ProgrammingProgramming

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. 

raja
Published on 14-Feb-2018 19:14:30
Advertisements