Files
2025PY/day09/02-break和continue.py
2025-05-22 16:50:44 +08:00

28 lines
741 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# continue和break关键字
# 关键字python内部约定的具有特殊用途的单词
# 程序的循环速度非常快利用continue和break关键字结束循环
# 1.break关键字(打断的意思)
# break关键字,可以直接结束循环,循环体内碰到break循环就结束
# 案例
num=1
while num<=10:
if num==5:
break # 只要num==5 break就执行 整个循环结束
print(f'这是第{num}次循环')
num +=1
# 2.continue关键字(继续的意思)
# continue关键字用于中断本次循环可以进入下一次循环
# 案例
num=0
while num<10:
num +=1
if num==5:
continue # 只要num==5 continue就执行 跳过本次循环 继续下一个循环
print(f'这是第{num}次循环')