示例:密码验证 8.3
Python
correct_password = "123456"
while True: # 条件永远为True,看似是死循环
user_input = input("请输入密码: ")
if user_input == correct_password:
print("密码正确,欢迎!")
break # 密码正确,用break跳出循环
else:
print("密码错误,请重新输入!")
# break后会执行到这里
print("程序继续...")