0
while True:

   x = False

   if x == False:
     if (float) <= (price):
        if not safe_mode:
            (Some function)
     x = True
     print(something)

   elif x == True:
     if (float) >= (price):
        if not safe_mode:
            (Some Function)
     x = False
     print(something)

that is my code, and i want that to loop, but what i get is 'x' doesn't want to change value to 'True'... and 'x = True' get grayed out. I don't know why it doesn't want to work, i need all your help pls. i kinda stress finding the problem :(

1
  • side note - you can/should use simply var instead of var == True in flow control statements. Commented Aug 17, 2018 at 7:32

1 Answer 1

5

The problem is that you set x back to False at the beginning of each iteration of the while loop, so its value is changed within each conditional block, but then changed back to False right after when the loop starts over.

Just set x = False outside of the while loop and that'll solve it. Example:

x = False

while True:
    # do stuff
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.