while loop - Cannot use (!=) to check char values -


im trying make while loop checks see if user inputted character correct. if character incorrect, loop supposed run until is. however, when enter loop cannot exit, if input correct value. appreciated!

if (userinputcheck == 'u' || userinputcheck == 'd' || userinputcheck == 'r' || userinputcheck == 'l'){          return userinputcheck;     }      else      while(userinputcheck != 'u' || userinputcheck != 'd' || userinputcheck != 'r' || userinputcheck != 'l'){          system.out.println("error. please enter u up, d down, r right, or l left");         string temp = keyboard.next();         userinputcheck = temp.charat(0);     }      return userinputcheck; 

a test x != 'u' || x != 'd' always true -- think it. if chracter entered u first test false, second true, whole thing true. want use && instead of ||:

while(userinputcheck != 'u' && userinputcheck != 'd' && ... 

once this, there's no need first if...


Comments

Popular posts from this blog

C++: Boost interprocess memory mapped file error -

python - IO.UnsupportedOperation: Not Writable -

python - malformed header from script index.py Bad header -