Sorry for my second post in such a short time, but I just wondered if there is something wrong here.
I was doing an exercise from a book which is pretty simple but it wasn't working correctly. The culprit was a do-while loop. A shortened version of the code is this:
For some reason, the loop never exits even though operator gets set to e or E. The code works perfectly fine if I change the while section to one of the following:
Am I unable to make comparisons in the do-while loops arguments? Since operator is equal to 'e' OR 'E' the loop should break, but it doesn't unless I remove the comparison.
I was doing an exercise from a book which is pretty simple but it wasn't working correctly. The culprit was a do-while loop. A shortened version of the code is this:
Code:
char operator;
do {
//do stuff here regarding the value of operator
}while ( (operator != 'e') || (operator != 'E') )
For some reason, the loop never exits even though operator gets set to e or E. The code works perfectly fine if I change the while section to one of the following:
Code:
while(operator != 'e') //here I only put in a lowercase e and it works
while(operator != 'E') //here I only put in an uppercase E and it works
while(toupper(operator) != 'E') //again, this works
Am I unable to make comparisons in the do-while loops arguments? Since operator is equal to 'e' OR 'E' the loop should break, but it doesn't unless I remove the comparison.