Break Statement in Python

 

Break Statement in Python
Break Statement in Python

Break Statement in Python

The break statement , it will terminate the iteration at the condition is satisfied

And execute the next statement

The break statement is used in both for and While.


Example

Break statement  in While Loop

    i = 0

    while i < 6:

        print(i)

        if i == 3:

            break

        i += 1


Output

    0

    1

    2

    3


Break statement  in For Loop

Example

    for letter in 'python':

        if letter =='h':

            break;

        print(letter)

Output

    p

    y

    t


Post a Comment (0)
Previous Post Next Post