python 跳出嵌套循环方法

class LoopError(Exception):pass

rs = ''
try:
    for i in range(1, 3):
        print i
        rs = 'one '
        if i == 1:
            for j in range(12, 22):
                print j
                if j == 13:
                    rs = 'bbs'
                    raise LoopError
except LoopError: #跳出,遇到LoopError
    print rs
    print 'good'
else: #循环完毕,没抛出LoopError
    print 'Not found'

 

posted @ 2013-07-25 16:23  践道者  阅读(2539)  评论(0编辑  收藏  举报