L
L
leham12021-08-27 23:00:09
Python
leham1, 2021-08-27 23:00:09

How to tell a loop to go back a few positions?

Hello. How to tell the loop to go back a few positions and continue from there?

Here is an example of what I want to do:

list_1 = ['1','2','3','4','5']
a = '4'
for i in list_1:
    if a == '4' and i == '4':
        print(i)
        # например здесь я хочу чтобы цикл вернулся на позицию, где  i = '2'. Как такое можно сделать?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-08-27
@leham1

i = 0
while i < len(list_1):
    v = list_1[i]
    i += 1
    ...
    if a == '4' and v == '4':
        i = 1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question