如何在python中突破double while循环?

luc*_*axi 3 python

新手蟒蛇在这里.如果用户选择"Q"进行"退出?",如何突破第二个while循环?如果我点击"m",它会进入主菜单,然后我就可以退出"Q"键.

while loop == 1:
    choice = main_menu()

    if choice == "1":
        os.system("clear")

        while loop == 1:
            choice = app_menu()

            if choice == "1":
                source = '%s/%s/external' % (app_help_path,app_version_10)
                target = '%s/%s' % (target_app_help_path,app_version_10)

            elif choice == "2":
                source = '%s/%s/external' % (app_help_path,app_version_8)
                target = '%s/%s' % (target_app_help_path,app_version_8)
            elif choice.lower() == "m":
                break
                loop = 0
            elif choice.lower() == "q":
                break
                loop = 0
            sendfiles(source, target)

    # Internal files

    elif choice == "q":
        loop = 0
Run Code Online (Sandbox Code Playgroud)

应用菜单方法:

def app_menu()
    print "Select APP version"
    print "-------------------"
    print "1) 11"
    print "2) 10"
    print "3) 8"
    print "m) Main Menu"
    print "q) Quit"
    print
    return raw_input("Select an option: ")
Run Code Online (Sandbox Code Playgroud)

Aph*_*hex 5

你几乎拥有它; 你只需要交换这两行.

elif choice.lower() == "m":
    break
    loop = 0

elif choice.lower() == "m":
     loop = 0
     break
Run Code Online (Sandbox Code Playgroud)

在设置之前,您将脱离嵌套循环loop.:)