how to restart "for" loop in python ?

for-loop, python, python-2.7

Solution

What about this:

x = [1,2,3,4,5,6]
restart = True
while restart:
    for i in x:
        # add any exit condition!
        # if foo == bar:
        #   restart = False
        #   break
        if i == 4:
           break
        else:
            print i

Problem

How can I do this in python: ``` x = [1,2,3,4,5,6] for i in x: if i == 4: -restart the loop from beginning- else: print i ``` So here it will print till 4 then repeat the loop

Original source

Related problems