title: Why does my prime number algorithm need a break in the for loop?
body: <p>I wrote an algorithm that populates a list with the first 1000 primes.</p>
  
  <p>When I run it like this, it populates the list with some numbers that aren't prime.</p>
  
  <pre><code>def is_prime():
      primes = [2]
      a = 0
      x = 3
      while a &lt; 999:
          for i in range(2, x):
              if (x % i) == 0:
                  x += 2
                  break
          else:
              primes.append(x)
              a += 1
              x += 2
      return primes
  
  
  print is_prime()          
  </code></pre>