# 循环之while循环
# 循环的语法与基本使用
"""
print(1)
while 条件:
代码1
代码2
代码3
print(3)
"""
# count=0
# while count<5: #5<5
# print(count) # 0,1,2,3,4
# count+=1 # 5
#
# print('顶级代码----->')
# 死循环与效率问题
# count=0
# while count<5: #5<5
# print(count) # 0,1,2,3,4
# while True:
# name=input('your name 》》》')
# print(name)
# 纯计算无io的死循环会导致致命的效率问题
# while True:
# print(1+1)
# while True:
# print('xxx')
#
# 循环的应用
# 1.重复代码
# 2.输对了应该不用再重复
# username = 'egon'
# pasword = '123'
# while True:
# inp_name = input('请输入您的账号:')
# inp_pwd = input('请输入您的密码:')
#
# if username == 'egon' and inp_pwd == pasword:
# print('登录成功')
# else:
# print('账号名或密码错误')
# 退出循环的两种方式
# 方式1:将条件改为false,等到下次循环判断条件时才会生效
# username = 'egon'
# pasword = '123'
#
# tag = True
# while tag:
# inp_name = input('请输入您的账号:')
# inp_pwd = input('请输入您的密码:')
#
# if inp_name == username and inp_pwd == pasword:
# print('登录成功')
# tag=False #之后的代码还会运行,下次循环判断条件时才生效
# else:
# print('账号或密码错误')
#
# print('=====end=====')
# 方式2:break.只要运行到break就会立刻终止本层循环
# username = 'egon'
# pasword = '123'
#
#
# while True:
# inp_name = input('请输入您的账号:')
# inp_pwd = input('请输入您的密码:')
#
# if inp_name == username and inp_pwd == pasword:
# print('登录成功')
# break # 立刻终止本层循环
# else:
# print('账号或密码错误')
#
# print('=====end=====')
# while循环嵌套
"""
tag=true
while tag:
while tag:
while tag:
tag=False
# 每一层都必须配一个break
while true:
while true:
while true:
break
break
break
"""
## break的方式:break后面的,在同一while循环的代码都不会再运行。
# # username = 'egon'
# pasword = '123'
#
# while True:
# inp_name = input('请输入您的账号:')
# inp_pwd = input('请输入您的密码:')
#
# if inp_name == username and inp_pwd == pasword:
# print('登录成功')
# while True:
# cmd = input("输入命令>:")
# if cmd == 'q':
# break
# print('命令{x}正在运行'.format(x=cmd))
# break
# else:
# print('账号或密码错误')
# 改变条件的方式
# username = 'egon'
# pasword = '123'
# tag=True
#
# while tag:
# inp_name = input('请输入您的账号:')
# inp_pwd = input('请输入您的密码:')
#
# if inp_name == username and inp_pwd == pasword:
# print('登录成功')
# while tag:
# cmd = input("输入命令>:")
# if cmd == 'q':
# tag=False
# else:
#
# print('命令{x}正在运行'.format(x=cmd))
# else:
# print('账号或密码错误')
# 8、whil +continue :结束本次循环,直接进入下一次
# 强调:在continue之后添加同级代码毫无意义,因为永远不会运行到他
# count=0
# while count<6:
# if count==4:
# count+=1
# continue
#
# print(count)
# count+=1
# 9、while + else
# 应用案列
# 案列1
username = 'egon'
pasword = '123'
# count=0
# tag=True
# while tag:
# if count==3:
# print('输入次数过多,退出循环')
# break
# inp_name = input('请输入您的账号:')
# inp_pwd = input('请输入您的密码:')
# if inp_name == username and inp_pwd == pasword:
# print('登录成功')
#
# else:
# print('您输入的账号或密码错误')
# count+=1
# 案例1优化
# count = 0
# while count < 3:
#
# inp_name = input('请输入您的账号:')
# inp_pwd = input('请输入您的密码:')
# if inp_name == username and inp_pwd == pasword:
# print('登录成功')
#
# else:
# print('您输入的账号或密码错误')
# count += 1
# else:
# print('输入次数过多,退出循环')
# 案列1加深
# tag=True
# count=0
# while count<3:
# inp_name = input('请输入您的账号:')
# inp_pwd = input('请输入您的密码:')
# if inp_name == username and inp_pwd == pasword:
# print('登录成功')
# while tag:
# cmd = input("输入命令>:")
# if cmd == 'q': # 整个程序退出,退出所有while循环
# tag=False
# else:
# print('命令{x}正在运行'.format(x=cmd))
#
# break
# else:
# print('您输入的账号或密码错误')
# count+=1
# else:
# print('输入次数过多,退出循环')