1. 程式人生 > >5.25 continue break for while

5.25 continue break for while

ont false auth 中斷 正常 print int 循環 ase

#_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