# [Closed] While statment igonred?

I’m programming a bishop piece in chess. I take x and y positions of it and then subtract both until one of them becomes 51 so that i get coordinates of the furthest place it will be able to move but the programm skips the whole while statment as if one of them would already be 51 (it’s not).

.png)

Personally, I’d introduce a so-called ‘print debug’ (assuming that you’re not using a decent IDE) just above the line: `while x != 51 or y != 51` as `print(f"x = {x} | y = {y}")` so that you can see what the values are before you hit that branch. If it’s good at that point, you’re not looking at the area of code that is throwing your script off.

I’m also not too sure about `while x < 408 and y < 408 and y > 51:`

Assuming that it all revolves around `408`, when you hit that second `while:` branch, both `x` and `y` would have a value of `51` (no?) and as such that second branch will not happen, because of `and y > 51`.

Just throwing it out there as a thought.

You want it to loop until x == 51 or y == 51, which is the same as while not (x == 51 or y == 51), or `while x != 51 and y == 51`.

You’re right. The range of positions is between 51 and 408 so the first place you can move will always have at least one veriable equal to 51. I also don’t know why I used “or” instead of “and”. Thanks!

Correct! Thanks.

1 Like

Language-agnostic reference question on Stack Overflow for the logical issue: if statement - Why does non-equality check of one variable against many values always return true? - Stack Overflow . The setup is slightly different, with slightly different consequences, but the problem is the same.

As an aside: I would strongly recommend against trying to use screen coordinates for game logic (moving the pieces around). Instead, use variables that track a conceptual position for the piece (i.e., coordinates on the chess board for the rank and file, which would range from 0 to 7), and translate to screen positions only in the code that draws the pieces. This will greatly simplify matters if you ever decide to change the board size, re-position the board within a larger window, support a resizable window, etc. etc. and will also make it easier to understand the game logic (since the screen size, after all, has nothing to do with how the pieces move).