Question: I have a loop starting with `for i in range(0, 100)`. Normally it runs correctly, but sometimes it fails due to network conditions. Currently I have it set so that on failure, it will `continue` in the except clause (continue on to the next number for `i`).

Is it possible for me to reassign the same number to `i` and run through the failed iteration of the loop again?

Answer: 
The clearest way would be to explicitly set `i`. For example:

```
i = 0
while i < 100:
    i += 1
    try:
        # do stuff

    except MyException:
        continue

```
```
for _ in range(5):
    try:
        # replace this with something that may fail
        raise ValueError("foo")

    # replace Exception with a more specific exception
    except Exception as e:
        err = e
        continue

    # no exception, continue remainder of code
    else:
        break

# did not break the for loop, therefore all attempts
# raised an exception
else:
    raise err

```

My version is similar to several of the above, but doesn't use a separate `while` loop, and re-raises the latest exception if all retries fail. Could explicitly set `err = None` at the top, but not strictly necessary as it should only execute the final `else` block if there was an error and therefore `err` is set.