Check if a value still remains the same in a While loop Python

后端 未结 4 1926
萌比男神i
萌比男神i 2021-01-27 01:23

I want know if there is a elegant method for looking if a value that continually changes in a while loop can be checked and stop the while loop if the value stops change and rem

4条回答
  •  死守一世寂寞
    2021-01-27 02:03

    You can:

    value_old = 0
    value_new = 1
    value = [value_old, value_new]
    while True:
        # change
    
        # test
        if value[0] == value[1]:
            break
        else:
            value = [value[1], value[0]]
    

提交回复
热议问题