title: Why does 'while' cause the program to run longer in Python
body: <p>I wrote a program to find out the primes in a list of numbers, just so practice formatting and all. Here is my code:</p>
  
  <pre><code>from math import *
  #Defining range to be checked
  a = range(1,10)
  #Opening empty list
  b = []
  #Wilsons method for primes
  for n in a:
      if ((factorial(n-1))+1)%n == 0:
          b.append(n)
  </code></pre>
  
  <p>This code runs without issue and fairly fast, at least at this stage of use. However, when I include a while statement(see below), it is substantially slower.</p>
  
  <pre><code>from math import *
  #Defining range to be checked
  a = range(1,10)
  #Opening empty list
  b = []
  #Wilson't method for primes
  for n in a:
      while n&gt;1:
          if ((factorial(n-1))+1)%n == 0:
              b.append(n)
  </code></pre>
  
  <p>Could anyone explain why that would be the case?</p>
  
  <p>n.b: I know there are more efficient method to find primes. I am just practicing formatting and all, although I don't mind improving my code.</p>
  
  <p>edit: mistaken addition of less than symbol rather than the appropriate greater than symbol. Corrected.</p>