Ok. So I am a total beginner at Java. But why does this loop never end, even if i type in 0 or 1.
do {
//Ask user to enter 1 or 0
System.out.print("Enter 1 or 0: ");
upOrDown = keyboard.nextInt();
} while(upOrDown != 0 || upOrDown != 1);
//Here the loop should exit if user entered 1 or 0, but it does not.
So, what am I missing here, probably very obvious and I am sorry 🙁
You need to do an
&&.You’re saying “If the number either isn’t 0 or isn’t 1, then retry.” This’ll always be true, however, as it cannot be both 0 and 1 at the same time.
So, this is what you want: