How to subtract the 'for' loop counter in Python?
Question: The structure that I know for the `for` loop in Python is as follows:

    
    
    for i in range(10)
    

and then range is actually `[0,1,2,3,4,5,6,7,9]`. Now there is a problem here
and that is I want to reduce the counter of my loop by putting a line `i-=1`,
however that does not show the result I expect.

The following example is a structure same as `while(True)` in e.g. Java and C,
but here it works and the counter in the loop ignores the line which was
intended to reduce it.

    
    
    for i in range(10):
        i-=1
        print i
    

And it generates the output:

    
    
    -1
    0
    1
    2
    3
    4
    5
    6
    7
    8
    

What should I do to get what I want with the `for` loop! I know it can be
easily done by a while as follows:

    
    
    i=0
    while(i<10):
       i-=1
       print i
       i+=1
    

Here is the Java code as an example and I expect to see an endless loop
printing `-1`:

Here is the Java code:

    
    
    import static java.lang.System.out;
    
        public class HelloWorld{
    
             public static void main(String []args){
                for(int i=0;i<10;i++)
                {
                    i--;
                    out.println(i);
                }
             }
        }
    


Answer: The `range` function takes 3 arguments: start, stop, and step:

    
    
    for i in range(-1, 9):
      yield i
    

To go in reverse

    
    
    for i in range(10, 0, -1):
      yield i
    

Take a look at the
[documentation](http://docs.python.org/2/library/functions.html#range).

**Edit:**

Of course, there's nothing to stop you from using the `range` directly. Thus
`map(print, range(10, 0, -1))` will print them all to the screen, while
`range(10, 0, -1)` will give you access to the integers directly.

