我正在使用一个我想无限循环的函数构建一个 while 循环。但我希望能够在输入某些内容时结束循环。如何创建一个无限循环,当你告诉它时它就会中断?
import time islooping = True counter = 1 while islooping == True: print("stillgoing " + str(counter)) counter += 1 time.sleep(2)
import time islooping = True counter = 1 while islooping == True: print("stillgoing " + str(counter)) input1 = input("Please add your input or type 'exit' to break the loop: ") if input1.lower() == "exit": break counter += 1 time.sleep(2)
输出: