title: While loop not working well
body: <p>Hi I have this code for selecting items from a python list. The problem is that once it loops over </p>
  
  <p>CODE:</p>
  
  <pre><code>import re
  name = input
  while True:
      name = input("Please enter your search term here:").lower()
      def FindName(name,list1):
          """ searches for a pattern in the list, returns the complete list entry. Is case       sensitive.
  May return incomplete value if ' is in the list value (ie confucius's)"""
      if name in list1:
          return name
      else:
          string1 = str(list1).replace('"',"'")
          pattern = re.compile("[']"+name+"[^']*")
          match = re.search(pattern,string1)
          if match:
              if match.group().lstrip("'") in list1:
                  return match.group().lstrip("'")
              else:
                  print 'Fail %s' %match.group().lstrip("'")
                  return None
          else:
              return ' '.join(name2) 
      china=['In', 'China', 'people', 'teach',"Confusius's",
      'teachings','dilligently.','Those',"Confusius''s",
      'teachings','are','called','Taoism.']
      india=['India', 'bopal', 'mahindra', 'gujarat',"gandhi's",
      'bombay',"Gandhi",]        ]
  
      name2 = name[:]
      this= ' '.join(name2)
      print FindName(this,china)
      for item in china:            
          print [(i,x) for (i,x) in enumerate(china) if x.startswith(this)]
      this = ' '.join(name2)
      for item in india:
          print [(i,x) for (i,x) in enumerate(india) if x.startswith(this)]
      this = ' '.join(name2)
      for item in india:
          print [(i,x) for (i,x) in enumerate(india) if x.endswith(this)]
      this = ' '.join(name2)
      for item in india:
          print [(i,x) for (i,x) in enumerate(china) if x.startswith(this)]
       loop continues......
  </code></pre>
  
  <p>The problem is that I have tried to put break on the loop but it still prints: <code>print [(i,x) for (i,x) in enumerate...</code> on every loop as it goes down the loop. How can I make it loop over the statements but only prints intended items without looping and printing <code>print [(i,x) for (i,x) in enumerate(china) if x.startswith(this)]</code> etc?</p>