title: while loop not terminating python
body: <p>i am writing an interactive program that displays y/n after selecting the option. if at begining itself i press s or c the while loop terminates. if i select some no first time &quot;say 5&quot; the 5th option turns to y but after that if i press &quot;s&quot; or &quot;c&quot; it shows the 5th entry as &quot;n&quot; and the program is not exited. not sure what's going wrong. beginner question.(alternate solution is also appretiated, can't import other packages as well)</p>
  <pre><code>import os,time
  selected_list=[]
  def px_filter_menu(num):
      os.system(&quot;clear&quot;)
      data = [&quot;p1&quot;,&quot;p2&quot;,&quot;p3&quot;,&quot;p4&quot;,&quot;p5&quot;,&quot;p6&quot;,&quot;p7&quot;,&quot;p8&quot;,&quot;p9&quot;,&quot;p10&quot;,&quot;p11&quot;,&quot;p12&quot;,&quot;p13&quot;,&quot;p14&quot;,&quot;p15&quot;,&quot;p16&quot;,&quot;p17&quot;,&quot;p18&quot;,&quot;p19&quot;,&quot;p20&quot;,&quot;p21&quot;,&quot;p22&quot;,&quot;p23&quot;,&quot;p24&quot;,&quot;p25&quot;,&quot;p26&quot;]
  
      print(&quot;============================================================================\n= Filter selection menu&quot;)
      print(&quot;============================================================================\n\n&quot;)
  
      gap =5
  
      for count , item in enumerate(data, 1):
          if count &lt;10:
              if data[count-1] in selected_list:
                  print(&quot;{0}.  {1} {2}&quot;.format(count,item.ljust(gap),&quot;[y]&quot;))
              else:
                  print(&quot;{0}.  {1} {2}&quot;.format(count,item.ljust(gap),&quot;[n]&quot;))
          else:
              if data[count-1] in selected_list:
                  print(&quot;{0}. {1} {2}&quot;.format(count,item.ljust(gap),&quot;[y]&quot;))
              else:
                  print(&quot;{0}. {1} {2}&quot;.format(count,item.ljust(gap),&quot;[n]&quot;))
  
      print(&quot;\n\n[S] save and exit&quot;)
      print(&quot;\n\n[C] if you press C and wish to make changes please remove the PX and add again\n&quot;)
  
      input = raw_input(&quot;enter the desired number &quot;)
      
      if len(input.strip()) ==0:
          print(&quot;first&quot;)
          time.sleep(2)
          px_filter_menu(-1)
         
      while True:
          if input.upper()==&quot;S&quot;:
              print(&quot;5&quot;)
              time.sleep(2)
              break
  
          elif input.upper()==&quot;C&quot;:
              del selected_list[:]
              #by default all protocol goes
              print(&quot;6&quot;)
              time.sleep(2)
              break
  
          elif input.isdigit() and data[int(input)-1] in selected_list:
              print(input)
              selected_list.remove(data[int(input)-1])
              print(&quot;3&quot;)
              time.sleep(2)
              px_filter_menu(-1)
  
          elif input.isdigit():
              selected_list.append(data[int(input)-1])
              print(&quot;4&quot;)
              time.sleep(2)
              px_filter_menu(-1)
          else:
              px_filter_menu(-1)
      return
  
  px_filter_menu(-1)
  </code></pre>