问题
Basically I want to stop a function but not by terminating the script.
While True:
do function A()
do function B()
if ( condition ):
function B.stop()
What I mean is when the condition is met, the while loop still runs but in the next iteration of the while loop, it only does function A, no longer does it do function B. I wonder if we can archive this in python? Thanks
回答1:
How about using a flag within the loop
flag = True
while True:
if flag:
do function B()
if condition:
flag = false
回答2:
Try this instead
continue_loop = True
While continue_loop:
do function A()
do function B()
if ( condition ):
continue_loop = False
来源:https://stackoverflow.com/questions/49155280/how-to-stop-a-function-in-a-while-loop-in-python