Home > Enterprise >  Is there a way to repeat a loop with same iteration?
Is there a way to repeat a loop with same iteration?

Time:09-21

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. 

CodePudding user response:

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"

  • Related