title: Very simple prime number test - I think I'm not understanding the for loop
body: <p>I am practicing past exam papers for a basic java exam, and I am finding it difficult to make a for loop work for testing whether a number is prime. I don't want to complicate it by adding efficiency measures for larger numbers, just something that would at least work for 2 digit numbers.</p>
  
  <p>At the moment it always returns false even if n IS a prime number.</p>
  
  <p>I think my problem is that I am getting something wrong with the for loop itself and where to put the "return true;" and "return false;"... I'm sure it's a really basic mistake I'm making...</p>
  
  <pre><code>public boolean isPrime(int n) {
      int i;
      for (i = 2; i &lt;= n; i++) {
          if (n % i == 0) {
              return false;
          }
      }
      return true;
  }
  </code></pre>
  
  <p>The reason I couldn't find help elsewhere on stackoverflow is because similar questions were asking for a more complicated implementation to have a more efficient way of doing it.</p>