Incrementing a for loop, inside the loop

后端 未结 4 953
伪装坚强ぢ
伪装坚强ぢ 2021-01-05 12:30

Is it possible to increment a for loop inside of the loop in python 3?

for example:

for i in range(0, len(foo_list)):
    if foo_list[i] < bar
            


        
4条回答
  •  Happy的楠姐
    2021-01-05 13:04

    while i < end:
      # do stuff
      # maybe i +=1
      # or maybe i += 4
    

    I suppose you could do this in a for loop if you tried, but it's not advisable. The whole point of python's for loop is to look at items, not indices

提交回复
热议问题