title: Why is this else: pass needed for processing to continue?
body: <p>Can someone explain why the <code>else: pass</code> shown below is needed in order for the rest of the code (the final <code>print 'processing...</code> statement) to be executed? Note the <code>print</code> in the <code>else</code> was put there just so I could tell that execution was indeed taking that path.</p>
  <p>It seems like that should happen whenever the <code>continue</code> isn't executed since code in the <code>else</code> does nothing. However, if I leave the <code>else</code> out, nothing further in the <code>for</code> loop appears to be executed when the condition is False -- when files with the extension <em>do</em> exist in the directory -- which doesn't make sense to me. The docs say <code>continue</code> &quot;continues with the next cycle of the nearest enclosing loop&quot;, fine, but if one is not executed, shouldn't processing proceed to the next statement?</p>
  <pre><code>import os
  
  source_dir = r'C:\Downloads'
  ext = '.mp3'
  
  for dirName, subdirList, fileList in os.walk(source_dir):
      if not any(os.path.splitext(fileName)[1].lower() == ext for fileName in fileList):
          print '  skipping &quot;{}&quot;'.format(dirName)
          continue
      else:  # why is this clause needed to continue this iteration of a loop?
          print 'contains   &quot;{}&quot;'.format(dirName)
          pass
  
      print 'processing &quot;{}&quot; which has &quot;{}&quot; files'.format(dirName, ext)
  </code></pre>
  <p><strong>Mystery Solved</strong></p>
  <p>The seemingly strange behavior was due to an indentation problem which is not visible in the code above nor normally in my text editor. It turned out that the last <code>print</code> statement was indented by 3 spaces then a tab, which makes it appear to align with the <code>else</code>, but in fact it either follows the <code>pass</code> in the <code>else</code> if it's there, or follows the <code>continue</code> in the first part of the <code>if</code>. Obviously confusing me a great deal.</p>
  <p>Here's a screenshot of the code in my text editor with its &quot;show space/tabs&quot; option turned on. The red dots represent spaces and the red right guillemet (<code>»</code>) represents a tab character:</p>
  <p><img src="https://i.stack.imgur.com/yZ3Y2.png" alt="screenshot of file in my editor showing bad indentation" /></p>