'break'
statement is used to come out of loop like for, while.
test.py
i = 0 while (1): i+=2 print(i) if(i==10): break else: print("Exiting loop") print("Finished Execution")
$ python3
test.py
2
4
6
8
10
Finished
Execution
As you
observe the output, print statement in else clause is not printed. It is
because, else clause will not execute, when a break statement terminates the
loop.
No comments:
Post a Comment