Iterate again within the for loop

前端 未结 7 1012
走了就别回头了
走了就别回头了 2021-01-21 07:50

is there a way to iterate again within the for loop? For example:

for x in list:
  if(condition):
      #I\'d like to grab the next iteration of the lis         


        
相关标签:
7条回答
  • 2021-01-21 08:49

    You can use a while loop instead of a for. In pseudocode:

    idx = 0
    while idx < length(list)
        x = list[idx]
        ...
        if (condition)
            idx += 1
        ...
        idx += 1
    
    0 讨论(0)
提交回复
热议问题