title: Python: while loop inside else
body: <pre><code>def is_prime(x):     
      count = 1
      my_list = []
      while count &gt; 0 and count &lt; x:
          if x % count == 0:
              my_list.append(x/count)
          count += 1
      return my_list
  my_list = is_prime(18)
  
  def prime(x):
  
      my_list2 = []
      for number in my_list:
          if number &lt;= 2: 
              my_list2.append(number)
          else:
              count = 2
              while count &lt; number:
                  if number % count == 0:
                      break
                  else: 
                      my_list2.append(number)
                  count += 1
      return my_list2
  print prime(18)
  </code></pre>
  
  <p>Just started out with Python. I have a very simple question. </p>
  
  <p>This prints: <code>[9, 3, 2]</code>. </p>
  
  <p>Can someone please tell me why the loop inside my else stops at count = 2? In other words, the loop inside my loop doesn't seem to loop. If I can get my loop to work, hopefully this should print <code>[2, 3]</code>. Any insight is appreciated!</p>