문제

first, I'd like to say I'm sorry because my english is not good enough but hopefully you'll understand me. I searched internet and couldn't find how to do this in python 2.7, I know it could be done with while loop but I'd like to know if it is possible to be done with for, also.

if we have a for loop that looks like this

for counter in range(0,len(list)):
    if (condition):
        var=something from dictionary

and i need to repeat the same iteration of loop if this condition is true. Tried with i=i-1 but that didn't work and I later found out that python creates a list of numbers on the beginning of a loop, tried xrange also but didn't work. So, does anyone know how to do this?

도움이 되었습니까?

해결책

What you need here is a while loop. It will be much easier for you to control the iterations inside the loop. You can structure it like this:

i = 0
while i < len(list):
    if condition:
        var = something from dictionary
    else:
        i++

다른 팁

have you tried

for l in list:
    if(condition):
        var=getValue()

for more examples details you will probably find a good examples at Python ForLoop

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top