title: Java: How to loop through an array and check that it matches a variable value?
body: <p>I have an argument which is of type char. I want to check that this char is lower case, if this is true then I will make a boolean variable equal true, otherwise, make it equal false. I have created an array of chars:</p>
  
  <pre><code>String argumentStr = args[2];
  char argument = argumentStr.charAt(0);
  boolean acceptArgument;
  
  char[] lowerCaseAlphabet = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
                              'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
  </code></pre>
  
  <p>Then I have tried two different solutions, but each is outside of the scope of my acceptArgument boolean.</p>
  
  <p>First:</p>
  
  <pre><code>for (int i = 0; i &lt; 27; i++) {
          if (argument == lowerCaseAlphabet[i]) {
              acceptArgument = true;
          } else {
              acceptArgument = false;
          }
      }
  </code></pre>
  
  <p>Second: </p>
  
  <pre><code>for (char letter: lowerCaseAlphabet) {
          if (argument == letter) {
              acceptArgument = true;
          } else {
              acceptArgument = false;
          }
      }
  </code></pre>
  
  <p>I understand why it won't work, because of the scope of the if statements compared with the acceptArgument boolean. But I don't know how to get around this. Please advise.</p>