break 完全终止
continue 跳出本次循环,执行下次循环。
# 猜年龄,猜三次。猜对就跳出 count = 1 while count <= 3: age = int(input("age:")) count += 1 if age >= 27: print("猜大了") elif age <= 25: print("猜小了") else: print("娶我回家吧!") break
# 猜年龄,猜三次。三次到后,回复 Y 可以继续猜三次,以此往复。回复 N 或者猜对就跳出。 count = 1 while count <= 3: age = int(input("age:")) count += 1 if age >= 27: print("猜大了") elif age <= 25: print("猜小了") else: print("娶我回家吧!") break if count == 4: number = input("number:") if number == "y": count -= 3 elif number == "n": print("再见") break