break Statement


The break keyword in python is used to bring the program control out of the current loop. So, when a break statement is encountered inside a loop, the loop is immediately terminated and the program control passes to the line immediately following the loop.

In case of inner loop, it breaks only from the inner loop and program continues to run in outer loop.

Syntax:

break;

Example:

    myList = [1, 2, 3, 4, 5]
    for num in myList:
        print(num)
        if num==3:
            print(“3 is found”)
            break

Output:

    1
    2
    3
    3 is found