Reputation: 545
I'm pretty sure this should work... But even if I enter a 0 or a 1 it still asks me to pick a colour. Am I being stupid or should it be exiting the loop if I enter a 0 or a 1?
public static int setColour() {
EasyReader keyboard = new EasyReader();
int colour;
do{
colour = keyboard.readInt("Pick a colour (black = 0, white = 1): ");
}while (colour != 0 || colour != 1);
return colour;
}
Upvotes: 2
Views: 64
Reputation: 1
Using || will never return the correct result. The && operator however will return your answer accurate.
Upvotes: 0
Reputation: 159754
Both conditions will never be satisfied simultaneously using the ||
operator. You want
} while (colour != 0 && colour != 1);
Upvotes: 7