35 Program to demonstrate while-else and break in Python

Program:

#while-else and break

x=1

while True:

    print("hello")

    if(x==5):

        break

    x=x+1

else:

    print("hai")

print("end")



#if break stmt is used in while loop then then control wont go to else block


Output:

 Program to demonstrate while-else and break in Python

Previous
Next Post »