Python Break and Continue statement is control statements executed inside a loop. The continue statement skips according to the conditions inside the loop and the break keyword terminate the loop execution at some point.
Break and Continue in Python
Simple example code of break and continue statements in Python.
A break statement is used inside both the
for loops. It terminates the loop immediately and transfers execution to the new statement after the loop. Exit loop when the variable count becomes equal to 3.
count = 0 while count <= 10: print(count) count += 1 if count == 3: print("Break") break
The continue statement causes the loop to skip its current execution at some point and move on to the next iteration.
for i in range(0, 5): if i == 3: print("continue") continue print(i)
0 1 2 continue 4
Do comment if you have any doubts or suggestions on this Python statement topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.