首页 > 代码库 > 5.25 continue break for while

5.25 continue break for while

#_author:"ljk"
#date: 2017/5/25

# 1、break,中断当前循环
# for i in range(10): #打印5-9
# if i < 5:
# continue #跳出当前循环
# print(i)
# for j in range(10):
# print("layer2",j)
# if j == 6:
# break


#2 break 一次只能中断一层循环
# for i in range(10): #打印5-9
# if i < 5:
# continue #跳出当前循环
# print(i)
# for j in range(10):
# print("layer2",j)
# if j == 6:
# break
# break #break一次最多只能中断一层的循环,再中断再break
#
#3

# exit_flag = False
# for i in range(10): #打印5-9
# if i < 5:
# continue #跳出当前循环
# print(i)
# for j in range(10):
# print("layer2",j)
# if j == 6:
# exit_flag = True#如果没有这一句,则运行结果同上,下一层循环不能执行
# break
# if exit_flag:#因为 exit_flag = True,所以才可以下一层的flag
# break #break一次最多只能中断一层的循环,再中断再break

# user1 = "ljk"
# password1 = "123"
# counter = 0
# while counter <3:
# user = input("USER:")
# password = input("PASSWORD:")
# if user ==user1 and password == password1:
# print("welcom")
# break
# else:
# print("please try again")
# counter += 1
# if counter == 3:
# keep_going = input("还想玩么?[y/n]")
# if keep_going == "y":
# counter = 0
# else: #while 循环正常结束后,会执行该else,如果break之后就不会执行
# print("Stop!不要脸的!")

5.25 continue break for while