← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #660366]: How to continously run a piece of code while simultaneously checking for a condition?

 

Question #660366 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/660366

    Status: Open => Answered

RaiMan proposed the following answer:
so if you want to leave the loop, when a condition is met, you have to use break.
If the loop does not have any condition to be check at every loop run beginning, the use while True (endless).
endless loops should have any terminating condition check in its body, so the script does not need to be killed by brute force.

#someCondition = None # not needed here
#while someCondition == None:
while True; # starts endless loop
    danceLeft()
    danceRight()
    danceAcrossTheHallway()
    if someRegion.exists(someImg, 1): # check terminating condition
        print("Stopped dancing; the image has appeared!")
        break
# next statement after loop is exited

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.