title: Return response during multi if in python
body: <p>I'm doing a <a href="http://flask.pocoo.org/docs/0.11/testing/" rel="nofollow">unit testing</a>, I'm checking fields in two databases collections so  during it I have to do a multi if conditions like this:</p>
  
  <pre><code>for doc1,doc2 in itertools.izip(docs1, docs2):
      if ... :
          if ... :
              response = 'Error'
          else:
              response = 'OK'
      else... :
          if ... :
              response = 'Error'
          else:
              response = 'OK'
      if ... :
          if ... :
              response = 'Error'
          else ... :
              response = 'OK'
      else ... :
          if ... :
              response = 'Error'
          else ... :
              response = 'OK'
  </code></pre>
  
  <p>so I want to assert a response if the error happened in one of this ifs, to give an answer like this:
   <code>self.assert400(response, message="Bad request, empty body.")</code> </p>
  
  <p>and when the whole process is okay to give an Ok response.</p>
  
  <p>All I want is to avoid writing this:</p>
  
  <pre><code>     if ... :
              if ... :
                  self.assert400(response, message="Bad request, empty body.")
              else:
                  self.assert200(response, message="OK.")
       else... : 
              if ... :
                  self.assert400(response, message="Bad request, empty body.")
              else:
                  self.assert200(response, message="OK.")
  </code></pre>
  
  <p>So what to achieve this?</p>
  
  <p>I thought to create an if condition in the end of it but that wouldn't stop the for loop?Please help me?</p>