1. break
effect : Used to jump out of the innermost layer for Loop or while loop , After leaving the loop, the program continues to execute after the loop code . namely break Statement can only jump out of the loop of the current level .
Example :
for i in "python":
for j in range(5):
print(i, end="")
if i == "t":
break
# The result of program execution is :pppppyyyyytooooonnnnn
This example shows ,break The statement jumps out of the innermost for loop , But you can also perform an outer loop .
2. continue
for i in "python":
if i == "t":
continue
print(i, end="")
# The result of program execution is :pyhon
for i in "python":
if i == "t":
break
print(i, end="")
# The result of program execution is :py
3. pass
for i in "python":
if i == "t":
pass
print(i, end="")
# The result of program execution is :python
4. for Circulation and while In the loop else Extended usage
for i in "python":
if i == "t":
continue
print(i, end="")
else:
print(" Program exit normally ")
# The result of program execution is : pyhon Program exit normally
for i in "python":
if i == "t":
break
print(i, end="")
else:
print(" Program exit normally ")
# The result of program execution is : py
matters needing attention : Remember break Statement and continue The difference between sentences
Articles you may be interested in :