0

I would like to know how do I start a for-loop from 0 if the if condition is True

for i in range (3):
   if a=1:
      #leave if-condition and start from beginning in for-loop with i=0

Break doesn't help here, because with break I only can leave the if Condition, but I also want to start the for loop from beginning.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
OneOrk
  • 1
  • 1

2 Answers2

0

You can try this instead of the for loop.

i = 0
while i < 3:
    if a == 1:
        i = 0
    i += 1

This keeps walking through the loop if a equals 1

-1

I think you may write like this

if 1 == a:
    for i in range(3):
        pass
yanghaogn
  • 833
  • 7
  • 15