title: Why does "Else" statement still print even if "IF" statement is true in nested for loop
body: <p>Why does my "ELSE" statement still prints even if my "IF" is always true</p>
  
  <p>I have an array wherein I am trying to search to see if there is a substring in it. When it does have that substring it should run another for loop with if and elif statements</p>
  
  <pre><code>test = ['SCHEDULE:1457H', 'SCHEDULE:1550H', 'SCHEDULE:1740H', 'SCHEDULE:1705H']
  task = ['ST:124', 'BROWSE:testB', 'DOWNLOAD:DLthis', 'REJECT:rejectme', 'APPROVE:goodtoGo', 'ST:123']
  
  while time.time() &lt; t_end:
      index = 0 
      for n in test:
          if "1457H" in n:
              for item in task:
                  if "ST" in task[index]:
                      print(task[index])
                      index += 1
                      time.sleep(2)
                  elif "LOGIN" in task[index]:
                      print(task[index])
                      index += 1
                  elif "BROWSE" in task[index]:
                      print(task[index])
                      index += 1
                  elif "DOWNLOAD" in task[index]:
                      print(task[index])
                      index += 1
                  elif "REJECT" in task[index]:
                      print(task[index])
                      index += 1
                  elif "APPROVE" in task[index]:
                      print(task[index])
                      index += 1
  
      else:  
          print("Sleeping")
          time.sleep(2)
  
  
  Results:
  
  ST:124
  BROWSE:testB 
  DOWNLOAD:DLthis 
  REJECT:rejectme
  APPROVE:goodtoGo
  ST:123
  Sleeping
  </code></pre>
  
  <p>Then repeats it again because of the while loop. I can't figure out why the "ELSE" statement still prints. I tried fixing the tab spaces of the "ELSE" statement and it still prints and even worse than the current Results.</p>