title: Iterating in a closed range [a, b] in python
body: <p>I want to iterate over a closed range of integers [a, b] in python, ie. iterating from a to b including both a and b. </p>
  
  <p>I know the following way of doing it:</p>
  
  <pre><code>for i in range(a, b+1):
      do_something(i)
  </code></pre>
  
  <p>For iterating in the reverse direction (ie. in the order b, b-1, b-2, ..., a), I do the following:</p>
  
  <pre><code>for i in range(b, a-1, -1):
      do_something(i)
  </code></pre>
  
  <p>I don't like this addition (b+1 in the example) and subtraction (a-1 in the example) to reach the closed end of the range. I find it less readable than the c/c++/Java counterpart (usage of <code>&lt;=</code> in a loop).</p>
  
  <p>Do you have something in python which can be used to iterate between the closed ranges without manual intervention of the boundaries?</p>