title: Loop with conditions in python
body: <p>Consider the following code in C:</p>
  
  <pre><code>for(int i=0; i&lt;10 &amp;&amp; some_condition; ++i){
      do_something();
  }
  </code></pre>
  
  <p>I would like to write something similar in Python. The best version I can think of is:</p>
  
  <pre><code>i = 0
  while some_condition and i&lt;10:
      do_something()
      i+=1
  </code></pre>
  
  <p>Frankly, I don't like <code>while</code> loops that imitate <code>for</code> loops. This is due to the risk of forgetting to increment the counter variable. Another option, that addressess this risk is:</p>
  
  <pre><code>for i in range(10):
      if not some_condition: break
      do_something()
  </code></pre>
  
  <p><strong>Important clarifications</strong> </p>
  
  <ol>
  <li><p><code>some_condition</code> is not meant to be calculated during the loop, but rather to specify whether to start the loop in the first place</p></li>
  <li><p>I'm referring to Python2.6</p></li>
  </ol>
  
  <p>Which style is preferred? Is there a better idiom to do this?</p>