1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 #Author: nulige 4 5 tag=True #設置tag控制他,只要一輸入Flash就退出整個循環 6 while tag: 7 print('level') 8 choice=input("levell>>: ").strip() 9 if choice == 'quit': break #quit 退出下一層循環,返回上一層循環 10 if choice == 'quit_all': tag = False #quit_all 退出所有循環 11 while tag: 12 print('leve12') 13 choice = input("leve12>>: ").strip() 14 if choice == 'quit': break 15 if choice == 'quit_all': tag = False 16 while tag: 17 print('level3') 18 choice = input("level3>: ").strip() 19 if choice == 'quit': break 20 if choice == 'quit_all': tag = False
執行結果:
1 level 2 levell>>: ss 3 leve12 4 leve12>>: ddd 5 level3 6 level3>: ccc 7 level3 8 level3>: quit 9 leve12 10 leve12>>: quit #返回上一層循環 11 level 12 levell>>: quit_all #退出所有循環