您的位置:首页 > 编程语言 > Python开发

python基础-牛逼的三层循环,实现想在那里退出,就在那里退出。

2016-12-13 10:05 302 查看
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#Author: nulige

tag=True      #设置tag控制他,只要一输入Flash就退出整个循环
while tag:
print('level')
choice=input("levell>>: ").strip()
if choice == 'quit': break               #quit        退出下一层循环,返回上一层循环
if choice == 'quit_all': tag = False   #quit_all   退出所有循环
while tag:
print('leve12')
choice = input("leve12>>: ").strip()
if choice == 'quit': break
if choice == 'quit_all': tag = False
while tag:
print('level3')
choice = input("level3>: ").strip()
if choice == 'quit': break
if choice == 'quit_all': tag = False


执行结果:

level
levell>>: ss
leve12
leve12>>: ddd
level3
level3>: ccc
level3
level3>: quit
leve12
leve12>>: quit      #返回上一层循环
level
levell>>: quit_all  #退出所有循环
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: