简体   繁体   中英

why does my python while loop infinitely?

I am trying to do a while loop that execute a function while the verification is not changed. my code looks like this:

from time import sleep

verif = 0
num = 5

def doso(num, verif):
    if num%11 == 0:
        verif += 1

    elif num%14 == 0:
        verif += 1

    print(num)
    return verif

while verif == 0:
    doso(num, verif)
    num += 1
    sleep(1)

so for now it run infinitely... i would like if it stoped when it find a multiple of 11 or 14

**its an example

Try updating the variable:

while verif == 0:
    verif = doso(num, verif)
    num += 1
    sleep(1)

To avoid running into an XY problem , note that you do not need verif at all. You can simply do:

num = 5

while True:
    if num%11 == 0 or num%14 == 0:
      break
    else:
      num += 1

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