Slight change to bool prime function
<p>A while ago I got an answer to a question on how to code a bool function to check if a number is prime: <a href="http://stackoverflow.com/questions/13512638/bool-function-for-prime-numbers">bool function for prime numbers</a>.</p>

<p>So from this, code that works is </p>

<pre><code>bool prime(int x)
{
if (x &lt; 2) return false;
for(int i=2; i&lt;= sqrt(x); i++) {
if ((x%i) == 0) return false;
}
return true;
}
</code></pre>

<p>However if I change the code to</p>

<pre><code>bool prime(int x)
{
if (x &lt; 2) return false;
for(int i=2; i&lt;= sqrt(x); i++) {
if ((x%i) != 0) return true;
}
return false;
}
</code></pre>

<p>It doesn't correctly determine whether a number is prime for many integers. I would of thought that these two segments of code would be equivalent. Is there any way of making this <code>bool prime</code> function work with <code>!=</code> ?</p>

<p>Thanks.</p>
