title: Is there a tool/solution to program a loop where the condition is only checked every X Iterations?
body: <p>For example: I have a function consisting of a while loop (this one would check for primes)</p>
  
  <pre><code>function isprime(int number){
  int i=2;
  int max= (int) sqrt(number)+1;
     while(i&lt;max){
         if(number%i==0){
            return 0;
         }
         i++;
     }
  return 1;
  }
  </code></pre>
  
  <p>I know this would be a very poor algorithm for testing primes, but my question focuses more on loops anyway. Currently a forth of the function's operations are "just" checking the condition. For larger numbers, this can be an awful lot. </p>
  
  <p>(Quick Example 1: If "number" is 1009, that would be checking the while condition 30 times, 30 operations for the index, and 29*2 operations for the if condition. That's 118 operations)</p>
  
  <p>I realize that I can just cut&amp;paste within the while condition and having the the index pass the maximum, while resulting in additional operations, doesn't falsify the return value. So if I cut everything starting from "if..." to "i++;" and paste it three (or n) times, checking the while condition would only take up 1/10 (or 1/(1+3n) of the operations, while creating a maximum of +2*3(or +(n-1)*3) unnecessary operations.</p>
  
  <p>(Quick Example 2: If "number" is 1009, that would mean checking the while condition  11 times, 33 operations for the index, and 33*2 operations for the if condition. That's 100 operations, 13 less)</p>
  
  <p>As I am currently experimenting with very big numbers (in layman's terms: "the condition will be false for a very, very, very long time") so pasting the if condition and the increment thousands of times would be useful, but very impractical - so my question is:</p>
  
  <p>Is there a tool (or a technique I am missing) to do that for me, but keeps the code clearly and easy to modify?</p>
  
  <p>Thanks in advance!</p>