title: Python Beginner's Loop (Finding Primes)
body: <p>I'm truly a beginner at python so I apologise for the lack of knowledge, but the reason I'm asking is that reading the Python manual and tutorial (<a href="http://docs.python.org/2.7/tutorial" rel="nofollow">http://docs.python.org/2.7/tutorial</a>) I'm not unable to totally grasp how loops work. I've written some simple programs so I think I get the basics but for whatever reason this program that is meant to list all primes less than or equal to n is not working:</p>
  
  <pre><code>n = int(raw_input("What number should I go up to? "))
  p = 2
  while p &lt;= n:
          for i in range(2, p):
                  if p%i == 0:
                          p=p+1 
          print "%s" % p,
          p=p+1
  print "Done"
  </code></pre>
  
  <p>The output when I enter 100 for example is:</p>
  
  <pre><code>2 3 5 7 11 13 17 19 23 27 29 31 35 37 41 43 47 53 59 61 67 71 73 79 83 87 89 95 97 101 Done
  </code></pre>
  
  <p>Which looks almost right but for some reason contains 27, 35, 95, which are composite of course. I've been trying to pick apart the way my loop works but I just don't see where it skips checking for divisibility suddenly. I figured that if someone had a look they could explain to me what about the syntax is causing this. Thanks a bunch!</p>