1

Is there a way to repeat a loop with same iterator without i incrementing by 1?

    for i in range(100):
        random_function()
        if status_code != 200:
            #repeat function with same iterator without incrementing by 1. 

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
wait3
  • 45
  • 6
  • use a `while True` or `for _ in range(100):` – cards Sep 21 '21 at 13:19
  • Does this answer your question? [Redo for loop iteration in Python](https://stackoverflow.com/questions/36573486/redo-for-loop-iteration-in-python) – no comment Sep 21 '21 at 13:21
  • 1
    This gfg article can help you with that :- [increment Iterator from inside the For loop](https://www.geeksforgeeks.org/ways-to-increment-iterator-from-inside-the-for-loop-in-python/) – MockinJay Sep 21 '21 at 13:30

1 Answers1

3

Use a while loop and control the increment yourself

i = 0
while i < 100:
    foo()
    if status == 200:
        i += 1

Or build the retry logic into your "random function"

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245