简体   繁体   中英

How can I loop "while"

I want to loop from "while flag: ~~" to the end of the code, but when I don't put "break." Only the last "for" phrase is repeated. How can I repeat the whole "while flag: ~~" part? I'm really noob;(

pyautogui.click(xxx,yyy)
colorlen = len(color)
for i in color:
    print(i)
dif = 10

while flag:

    pyautogui.moveTo(xxx, yyy)
    pyautogui.click(xxx, yyy)

    index = index + 1
    iter_num += 1

    img = ImageGrab.grab()
    for i in range(left_top[0], right_bottom[0], 2):
        if flag == True:
            for j in range(left_top[1], right_bottom[1], 2):
                rgb = img.getpixel((i,j))
                if flag == True:
                    for ss in range(colorlen): 
                        if(abs(rgb[0] - color[ss][0]) <= dif and abs(rgb[1] - color[ss][1]) <= dif and abs(rgb[2] - color[ss][2]) <= dif):
                            pyautogui.moveTo(i,j)
                            pyautogui.click(i+1,j+1)                    
                            pyautogui.moveTo(selx,sely)
                            pyautogui.click(selx,sely)
                            pyautogui.press('enter')

All the fors and the while loop are necesseraly repeated while the flag value is non empty.

If not, that means that something in your indented fors is looping on itself and "blocking" something.

Plus, your second if flag == True seems useless unless the flag value can be changed between your two ifs.

So check if something in your while loop isn't blocking the loop.

The fastest way to be sure is to log or print in while beginning

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM