title: Python code seems to be getting executed out of order
body: <p>At work I have a programming language encoded in a database record. I'm trying to write a print function in python to display what the record contains. </p>
  
  <p>This is the code I'm having trouble with:</p>
  
  <pre><code>    # Un-indent the block if necessary.
      if func_option[row.FRML_FUNC_OPTN] in ['Endif', 'Else']:
          self.indent = self.indent - 1
  
      # if this is a new line, indent it.
      if len(self.formulatext) &lt;&gt; 0 and self.formulatext[len(self.formulatext) - 1] == '\n':
          for i in range(1,self.indent):
              rowtext = '    ' + rowtext
  
      # increase indent for 'then', 'else'
      if func_option[row.FRML_FUNC_OPTN] in ['Then', 'Else']:
          self.indent = self.indent + 1
  </code></pre>
  
  <p>When row.FRML____FUNC____OPTN equals 'Else', I expect it to first un-indent, then indent again, so that the 'else' is printed at a lower level of indentation, then the rest of the code is within. Instead this is the type of indentation I get:</p>
  
  <pre><code>IfThen
          IfThen
              Else
          EndifComment
          IfThen
          Endif
          IfThen
              Else
          Endif
      Else
  Endif
  </code></pre>
  
  <p>As you can see the 'Else' is still indented higher than the If / Endif. Any idea why this could be happening?</p>
  
  <p>I did try sprinkling the code with debug statements the result of which is: </p>
  
  <pre><code>row:     Else
  row.FRML_FUNC_OPTN is : Elsedecrementing indent
  row.FRML_FUNC_OPTN is : Elseincrementing indent
  </code></pre>
  
  <p>which means that the indent altering if's are indeed being entered...</p>