title: Iterating over an empty list
body: <p>Trying to iterate over a list that based on previous conditions, may or may not be empty.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>function_name(): 
      for x in gen:
          if x = attacker1:
              gain += 2
          elif x = attacker2:
              gain += 3
          else:
              gain -= 1
      if not gen:
          gain -= 1
      return gain
  </code></pre>
  
  <p>When one of the variables is present in the list, the code works. When no variables are present, the codes does not work and I get the following error message:</p>
  
  <p><em>ErrorMessage: local variable 'gain' referenced before assignment</em></p>
  
  <p>I've also tried:</p>
  
  <pre><code>function_name():      
        for x in gen:
            if x = attacker_1:
                gain += 2
            elif x = attacker2:
                gain += 3
            else:
                gain -= 1
        if gen == False:
            gain -= 1
        return gain
  </code></pre>
  
  <p>The above code gives me the same error message.</p>
  
  <p>Also, not sure if I need the "else" statement in the for loop, but I put in there to be safe. </p>
  
  <p>Any help is much-appreciated. Thank you!</p>