[root@80sa python]# cat test.py 
#!/usr/bin/env python
#coding:utf-8

import sys
for x in range(1,22):
    print x
    if x == 3:
       	print "hello 3!"
       	continue #跳出当前循环
    if x == 6:
       	break      #当X=6的时候 就中断循环操作,但还是会继续执行下一个for循环
    if x == 5:
       	sys.exit() #这里是退出整个程序语句块,不执行下面的for循环
    print "#"*10
else:
    	print "ending"


for x in range(1,22):
    	print x
else:
    	print "ending"   #当for循环正常结束的时候,会执行else语句块,否则将不执行

  

相关文章:

  • 2021-08-16
  • 2022-12-23
  • 2022-12-23
  • 2021-08-09
  • 2021-12-29
  • 2021-08-27
猜你喜欢
  • 2022-02-19
  • 2021-11-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-14
  • 2021-11-01
相关资源
相似解决方案