循环语句while和for语句

1、while循环

count=0
while True:
    print("count:",count)
    count=count+1
#循环终止条件 if count==5:
#结束整个循环
break
运行结果

count: 0
count: 1
count: 2
count: 3
count: 4

2、for循环

for in range(循环初始值,循环中止条件,循环步长)
      print("loop:",i)

3、循环嵌套

for i in range(0,10):
      print("----------",i)
      for j in range(0,10):
      print(j)
      if j>5:
         break
运行结果(外层循环10次,内层循环4次)
---------- 0
0
1
2
3
---------- 1
0
1
2
3
---------- 2
0
1
2
3
---------- 3
0
1
2
3
---------- 4
0
1
2
3
---------- 5
0
1
2
3
---------- 6
0
1
2
3
---------- 7
0
1
2
3
---------- 8
0
1
2
3
---------- 9
0
1
2
3

 

posted @ 2018-07-09 22:39  冷璇  阅读(69)  评论(0)    收藏  举报