Python3学习笔记-24(break和continue语句)

break语句

break 语句可以跳出 for 和 while 的循环体。

例:

a = 10
while a > 0:
    print('执行了!')
    break
    print('这句执行嘛?')

输出结果如下:

执行了!

continue语句

continue语句被用来告诉Python跳过当前循环块中的剩余语句,然后继续进行下一轮循环。

name = "xiaoxiao"

for temp in  name:
    if temp == "i":#只要遍历的字母为i,跳过此次循环,进行下一次循环
        continue
    print(temp) #输出当前字母

输出结果如下:

x
a
o
x
a
o


猜你喜欢

转载自blog.csdn.net/u012430402/article/details/80963653