break语句;continue语句
# break:跳出while或for循环,当循环执行到break时,循环彻底结束。 # 注:break只能控制离他最近的那层循环 # break:循环语句有else语句时,当在循环语句中执行到break时,循环 # 彻底结束,else语句也不再执行。 ''' for i in range(5): if i == 2: break print(i) ''' ''' for i in range(5): if i == 2: break for j in range(3): if j == 1: break print(i,'-',j, end=" ") print() ''' for i in range(5): if i == 2: break print(i) else: print("哈哈,你看,下雨了") # continue:当循环执行到continue时,结束本次循环,不影响下一次的循环 # continue: 只能控制离他最近的循环 ''' for i in range(7): print(i) if i == 3: continue print("我在数字下面") ''' for i in range(5): for j in range(5): if j == 3: continue print(i,"-", j, end=" ") print()