What I said above notwithstanding, just because a variable can only take two values does not necessarily mean it should be made a bool. A bool can not take any two values, it can only take the values true and false. This is a good use of bool:
Code:
bool found = false;
for (int i=0; i<n; i++) {
if (t[i] == SOME_VALUE) {
found = true;
}
}
This is a bad one:
Code:
bool turn = true;
for (;;) {
/* Play */
turn = !turn;
}
it should be:
Code:
#define WHITE 1
#define BLACK 0
int turn = WHITE;
for (;;) {
/* Play */
turn = (turn == WHITE) ? BLACK : WHITE;
}
A good rule of thumb is: add a question mark after the name of your variable. If you can answer the resulting question with yes or no, make it a bool. Otherwise, don't.
Bookmarks