1、利用False来结束while循环语句:
age = 50 # user_input_age = int(input("Age is :")) flag = True while flag: user_input_age = int(input("Age is :")) if user_input_age == age: print("Yes") flag = False elif user_input_age > age: print("Is bigger") else: print("Is smaller") print("End")
2、利用break 来结束while循环语句:
# break 终止 age = 50 # user_input_age = int(input("Age is :")) # flag = True # break while True: user_input_age = int(input("Age is :")) if user_input_age == age: print("Yes") break elif user_input_age > age: print("Is bigger") else: print("Is smaller") print("End")