python基础之break

break是终止本次循环,比如你很多个while循环,你在其中一个while循环里写了一个break,满足条件,只会终止这个while里面的循环,程序会跳到上一层while循环继续往下走

1 for i in range(10):
2   print("-----%d-----" %i)
3   for j in range(10):
4     if j > 5:
5       break
6     print(j)

-----0-----
0
1
2
3
4
5
-----1-----
0
1
2
3
4
5
-----2-----
0
1
2
3
4
5
-----3-----
0
1
2
3
4
5
-----4-----
0
1
2
3
4
5
-----5-----
0
1
2
3
4
5
-----6-----
0
1
2
3
4
5
-----7-----
0
1
2
3
4
5
-----8-----
0
1
2
3
4
5
-----9-----
0
1
2
3
4
5

 

1 while True:
2     print("aaaa")
3     print("bbbb")
4     break
5     print("cccc")
6 print("dddd")

aaaa
bbbb
dddd

 

count = 1
while True:
    print(count)
    count+=1
    if count>100:break

 

posted @ 2018-07-18 20:37  雪哥  阅读(160)  评论(0)    收藏  举报