title: Is it possible to concisely use a complex condition for a while loop?
body: <p>I am working on a game where I utilize a class that will allow a user to input a choice as a string to do one of 3 options: "attack", "defend", or "flee". This can be logically handled by the 'exclusive OR' (XOR). I decided to try using a while loop using this logic instead of the usual Switch construct to see what happens, being armed with just a little bit of discrete math. I knew the while condition would be ugly and long, but it works dammit!, and I like it! I was wanting to know, since I would like to reuse this while loop in other sections of the code if there was some way to save the while loop condition (like as a variable, method or something) so that I can put it in the while loop condition and not take up 8 lines of code each time. Here is my while loop. Don't laugh, it works. AND, it avoids try-catch. It actually runs very cleanly. I posted the method that I use below. This method is called by another class:        </p>
  
  <pre><code>public static void fighterAction(){  
      String selection = null;
      Scanner userChoice = new Scanner(System.in);
  
  //Fighter 1 chooses combat action to perform: this is performed by 
  //(XOR) logic:
  //(( a  || b ) &amp;&amp; !( a &amp;&amp; b ) || c ) &amp;&amp; !((( a || b ) &amp;&amp; !( a &amp;&amp; b ) &amp;&amp; c ))
  
      while((( !"attack".equals(selection)  || !"defend".equals(selection) ) 
              &amp;&amp; !( !"attack".equals(selection) &amp;&amp; !"defend".equals(selection)
              ) || !"flee".equals(selection) ) &amp;&amp;
              !((( !"attack".equals(selection) || !"defend".equals(selection)
              ) &amp;&amp; !( !"attack".equals(selection) &amp;&amp; 
              !"defend".equals(selection) ) &amp;&amp; !"flee".equals(selection) )))
      {    
          System.out.println("Choose action: attack  defend  flee\n\nEnter: ");
          selection = userChoice.next();
          if((( !"attack".equals(selection)  || !"defend".equals(selection) ) 
                  &amp;&amp; !( !"attack".equals(selection) &amp;&amp; 
                  !"defend".equals(selection) ) || !"flee".equals(selection) )
                  &amp;&amp; !((( !"attack".equals(selection) || 
                  !"defend".equals(selection) ) &amp;&amp; 
                  !( !"attack".equals(selection) &amp;&amp; 
                  !"defend".equals(selection) ) &amp;&amp; 
                  !"flee".equals(selection) )))
          {
              System.out.println("Invalid Entry!");
          }else{
          System.out.println(selection + " was chosen");
          System.out.println("");
          }
      }        
  }
  </code></pre>
  
  <p>Again, I am asking if there is a way to take this while clause (which I emphasize, works perfectly):        </p>
  
  <p>(( !"attack".equals(selection)  || !"defend".equals(selection) ) &amp;&amp; !( !"attack".equals(selection) &amp;&amp; !"defend".equals(selection) ) || !"flee".equals(selection) ) &amp;&amp; !((( !"attack".equals(selection) || !"defend".equals(selection) ) &amp;&amp; !( !"attack".equals(selection) &amp;&amp; !"defend".equals(selection) ) &amp;&amp; !"flee".equals(selection) ))   </p>
  
  <p>so that it fits inside of the while loop condition:</p>
  
  <pre><code> while(FITS HERE){}  
  </code></pre>
  
  <p>Thanks!      </p>