title: Why is my loop infinite? I have tested with 91
body: <p>I am checking if a number is prime by only checking if any odd number from 3 up to its sqaure root is it's factor, once it has one then the number isn't prime. I don't understand why my loop is seemingly infinite.</p>
  
  <p>I have added cout lines to see where there problem begins and it does not really show</p>
  
  <pre><code>int countFactors(int num)
  {
      cout &lt;&lt; "Inside prime\n";
      int factors = 0, x = 0, i;
      x = int(sqrt(num));
      for (i = 3; i &lt;= x; i += 2)
      {
          cout &lt;&lt; "Inside prime for \n";
  
          while(factors &lt; 1)
          {
              cout &lt;&lt; "Inside Prime while";
              if (num % i == 0)
              {
                  factors++;
              }
          }
      }
      return factors;
  }
  </code></pre>
  
  <p>I am expecting the function to receive any number from 19 upwards, check if it has any factor of odd numbers from 3, once the factor is found the loop exits because the number is NOT odd since 1 itself and an extra number are factors. the functions returns 0 for prime or 1 not prime.</p>