title: Why does the code not work in this instance?
body: <p>I am struggling to understand why code wouldn't work. According to the truth table/logic gates for AND and OR <a href="https://en.wikipedia.org/wiki/Truth_table" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Truth_table</a> I would assume that I would be able to have an if statement inside the <code>for</code>-loop such that <code>(p &lt; 2 || p % i == 0)</code> would work for finding prime numbers but it fails when considering negative numbers.</p>
  
  <p>I know that if you if take out the <code>p &lt; 2</code> and write it as an if statement outside this <code>for</code>-loop it works, but if the <code>p &lt; 2</code> is inside the <code>for</code>-loop it does not work. Why is this so?</p>
  
  <pre><code>public class test {
      public static void main(String [] args) {
          System.out.println("Hello World!");
  
          int a = 7;
          System.out.println("A is Prime: " + isPrime(a));
          System.out.println();
  
          int b = 4;
          System.out.println("B is Prime: " + isPrime(b));
          System.out.println();
  
          int c = -7;
          System.out.println("C is Prime: " + isPrime(c));
          System.out.println();
  
          int d = 53;
          System.out.println("D is Prime: " + isPrime(d));
      }
  
      public static boolean isPrime(int p) {
          for (int i = 2; i &lt; p; i++) {
              if (p &lt; 2 || p % i == 0) {
                   return false;
              }
          }
          return true;
      }
  }
  </code></pre>