-3

I'm trying to get my loop to check for one thing multiple times, and if a value surpasses another value, it ends and goes to the next loop.

What I have right now is this:

x = 1
a = 7
complete = False
while complete == False:
    click(Im using sikulix so theres an image of what its supposed to click here)
    x == x+1
    if x > a:
        complete == True
    else:
        complete == False

What doesn't work with this script is that the loop doesn't end, it just keeps going. I've tried putting a break after the complete == True but it doesn't change anything. What could I change to make this work as expected?

Waffle
  • 1
  • 1
  • 2
    Typo: `==` is comparison, use `=` for assignment. – Barmar Jul 12 '23 at 23:35
  • 2
    Why not `for x in range(1, a+1):`? – Barmar Jul 12 '23 at 23:36
  • 1
    You need to learn basic debugging, like adding `print(x)` into the loop. Then you would have seen that you weren't incrementing properly. https://ericlippert.com/2014/03/05/how-to-debug-small-programs/ – Barmar Jul 12 '23 at 23:37
  • 1
    Don't compare to True and False. Do `while not complete:`. It reads better. Also, you can say `complete = x > a` instead of your if, but you can skip `complete` altogether by doing `while x <= a:`, and at that point you should just move to @Barmar's version. – Tim Roberts Jul 12 '23 at 23:48

1 Answers1

0

Typo: == is comparison, use = for assignment.

– Barmar

I did not know this, thanks! (I'm still very new to coding)

Waffle
  • 1
  • 1
  • 1
    But you did know it, because the first three lines of that code use `=` the right way for assignment. – John Gordon Jul 13 '23 at 00:30
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 14 '23 at 21:07