title: Stop iteration from inside a function
body: <p>I am using an iterator to flexiblily go through a collection. In my function there are several cases in which the function gets a new item and processes them. So there are several cases in which something like this happens:</p>
  
  <pre><code>it = iter(range(10))
  while condition:
      try:
          item = next(it)
          item.do_many_different_things()
      except StopIteration:
          break
  </code></pre>
  
  <p>And that makes everything extremly messy, so I wanted to move it into a seperate methode. But than I can't use break, because python doesn't know what loop it should break. So far I'm returning a None type, and break the loop if a None was returned. But is there a more elegant solution?</p>