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

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -