How to break out of multiple loops?

后端 未结 30 3261
情书的邮戳
情书的邮戳 2020-11-21 05:48

Given the following code (that doesn\'t work):

while True:
    #snip: print out current state
    while True:
        ok = get_input(\"Is this ok? (y/n)\")
          


        
30条回答
  •  粉色の甜心
    2020-11-21 06:23

    Here's an implementation that seems to work:

    break_ = False
    for i in range(10):
        if break_:
            break
        for j in range(10):
            if j == 3:
                break_ = True
                break
            else:
                print(i, j)
    

    The only draw back is that you have to define break_ before the loops.

提交回复
热议问题