Decrement a variable in an incrementing for loop
<p>In my python script, I am itterating through a list (headerRow) starting at index 9. I want to check to see if it is already in the database, and if not then add it to a database with an auto-incementing primary key. I then want to send it through the loop again to retrieve it's primary key.</p>

<pre><code>for i in range (9, len(headerRow)):
    # Attempt to retrieve an entry's corresponding primary key.
    row = cursor.fetchone()
    print i

    if row == None: # New Entry
        # Add entry to database
        print "New Entry Added!"
        i -= 1 # This was done so that it reiterates through and can get the PK next time.
        print i

    else: # Entry already exists
        print "Existing Entry"
        qpID = row[0]
        # ...
</code></pre>

<p>Here is the output of my script:</p>

<pre><code>9
New Question Added!
8
10
New Question Added!
9
11
</code></pre>

<p>As you can see, my issue is that range() doesn't care what the existing value of <code>i</code> is. What is the preferred python way to do what I'm trying to do?</p>

<p>Thanks in advance,</p>

<p>Mike</p>
