title: Python: How to tell the for loop to continue from a function?
body: <p>Sometimes I need the following pattern within a <code>for</code> loop. At times more than once in the same loop:</p>
  <pre><code>try:
      # attempt to do something that may diversely fail
  except Exception as e:
      logging.error(e)
      continue
  </code></pre>
  <p>Now I don't see a nice way to wrap this in a function as it can not <code>return continue</code>:</p>
  <pre><code>def attempt(x):
      try:
          raise random.choice((ValueError, IndexError, TypeError))
      except Exception as e:
          logging.error(e)
          # continue  # syntax error: continue not properly in loop
          # return continue  # invalid syntax
          return None  # this sort of works
  </code></pre>
  <p>If I <code>return None</code> than I could:</p>
  <pre><code>a = attempt('to do something that may diversely fail')
  if not a:
      continue
  </code></pre>
  <p>But I don't feel that does it the justice. I want to tell the for loop to <code>continue</code> (or fake it) from within <code>attempt</code> function.</p>