break语句用来终止循环语句
如果您使用嵌套循环,break语句将停止执行最深层的循环,并开始执行下一行代码。
def f(): for i in range(10): for j in range(10): # 中断该层循环 print(i,j) if j == 4: break
continue 语句跳出本次循环
跳过当前循环的剩余语句,然后继续进行下一轮循环。
def f(): for i in range(10): for j in range(10): # 跳出该层循环的 j=4后的剩余语句 if j ==4: continue print(i,j)