I don't know whats wrong with my do...while loop, its the one at the last function

What I want is that it only exits if the move is between 0-8 and and that the board[move] is EMPTY, well when creating the the vector board I initialized all of its element to EMPTY but after then I initialized the board[0] to X now when at the do...while loop at my last function I enter 0 it exits the loop ? Why ? It shouldn't, because board[0] is equal to X not EMPTY the first condition in the do...while loop is working correctly but not the second one.

What am I doing wrong ?

EDIT: Sorry for the wrong thread name it should be Do...While loop problem

@laserlight:your solution works perfectly everything is as I expected, but i dont understand why the || instead of &&, I want both of the conditions to be true not only one

Code:

while ((!(move >= 0 && move <= 8)) && (board[move] != EMPTY))

Doesn't my condition says this:
That While move is not greater than or equal to 0 and move is not less than or equal to 8 and board[move] (in my case board[0]) is not equal to EMPTY continue looping.

When move is 0, then it is greater than 0 and is equal to 0 ( this means the first condition becomes false) and board[move] is is not equal to EMPTY, that is the second condition is still true, it should continue looping but it doesn't and it exits

Not only is this easier to write, but it is also easier for others to understand, which helps EVERYONE. I hate it when you find a really complicated condition in a loop. It is much better if the code is clearer. And the error messages are now clearly indicating what is wrong with the move too.

Some programmers feel that break and continue violate structured programming. The effects of these statements can be achieved by structured programming techniques. Most programmers consider the use of break in switch statements acceptable.

I may have problem reading complex conditions, in fact I have problem. But I request you to explain me the problem with my condition, as I didn't got the point. So in future I may avoid things like this

I do agree that break and continue can lead to spaghetti-code too. You could, instead of using break, use a "done = 1;", [initializing with "done = 0" before the loop], and use "while(!done)" or some similar construct.

You just have to break it down:

Code:

while ((!(move >= 0 && move <= 8)) && (board[move] != EMPTY))

Becomes:

Code:

!(move >= 0 && move <= 8)

So that is true if move is less than 0 or greater than 8.

Code:

board[move] != EMPTY

True if board[move] is not EMPTY

For the whole condition to be true, both conditions need to be true. In this case, that's undefined, since if move is out of range, board[move] is undefined (and should not be tested). You need to continue if the move is out of range OR the board position isn't empty.