码迷,mamicode.com
首页 > 其他好文 > 详细

break和continue的使用

时间:2016-08-11 20:50:21      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:

学习关于break和continue的使用

1.使用while,输出从a到b的所有数字

# print all numbers from a to b
a = 5
b = 10

while True:
    if a >= b:
        print a 
        break
    else:
        print a 
        a += 1
print "Test is over."
# print all numbers from a to b
a = 5
b = 10

while a <= b:
    print a
    a += 1
    
print "Test is over."
    
    

 用for循环实现

a = 5
b = 10

for a in range(a, b + 1, 1):
    print a
    a += 1
    
print "Test is over."
    
    
# print all numbers from a to b
a = 5
b = range(5, 11, 1)

for a in b:
    print a
    a += 1
    
print "Test is over."
    
    

2.continue

  退出当前循环,进入下一个循环

  to be continued

break和continue的使用

标签:

原文地址:http://www.cnblogs.com/nopear/p/5762267.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!