OR condition not working inside While loop

Hi,

I am making a menu selection via LCD display and keypad.

the idea is that the program is waiting for the input of specifically the char "*" or "#" if none of these appears, it it inside the loop.

I am able to do this for one condition only, but not for both:

      lcd.print("Standard program"); 
      lcd.setCursor(0, 1);
      lcd.print("*=YES #=NO"); 
      char key = keypad.getKey();
      while( key != '*'  )  // or  while( key != '#'  )
      {
         key = keypad.getKey(); //UPDATE VALUE 
      }
      lcd.clear();

substantially I cannot do

while( key != '*' || key != '#' )

if I do that the program is not proceeding, the condition is not met.
Any idea why?
Or how can I solve this?

Hi

Try a switch. See This reference page

Cheers

Start here

That's because if it's not a '' or not a '#' you effectivly made a true :wink: Becasue if you have a '' it will be true because '' != '#'. And if you have a '#' the first part will be true because '#' != ''. And for every other character both are true.

Aka, what you wanted was:

while(key != '*' && key != '#')

Figured out, it should be AND

while( key != '*' && key != '#' )