break & continue
break跳出并结束当前整个循环,执行循环后的语句
continue结束当次循环,继续执行后续次数循环
for c in "python":
if c == "t":
continue
print(c, end='')
遍历“python”中的字符串,如果没有遇到‘t’,则把每个字符打印出来,如果遇到‘t’,继续执行遍历循环。打印结果为‘pyhon’
for c in "python":
if c == "t":
break
print(c, end='')
如果遇到了‘t’,则跳出整个循环,打印结果为‘py’
一个break保留字只能跳出当前一层循环,如果有多层循环嵌套,它只能跳出内层循环,外层循环仍然执行。