I have a while loop i wish to escape when i hit the number 1 through 5.
What would be the best statement to put for that?
I currently have this.
while ( oneChoice!= 1 || oneChoice!= 2 || oneChoice!= 3 || oneChoice!= 4 || oneChoice!= 5 )
{
cout << "Please make a selection" << endl;
cout << "Choose once more: ";
cin >> oneChoice;
break;
}
Assuming
oneChoiceis anint(and thus can’t have a value between 1 and 2, for example), just change the conditional to:or, equivalently:
Additionally, if
oneChoicehas no real meaning or importance before entering the loop, it would probably be better practice to use ado { ... } while (oneChoice < 1 || oneChoice > 5);loop instead.