You could use a while loop and increment i
based on the condition:
while i < (len(foo_list)):
if foo_list[i] < bar: # if condition is True increment by 4
i += 4
else:
i += 1 # else just increment 1 by one and check next `foo_list[i]`
Using a for loop i
will always return to the next value in the range:
foo_list = [1,2,3,4,5,6]
bar = 6
for i in range(len(foo_list)):
print("range i ",i)
if foo_list[i] < bar:
i += 4
print("if i",i)
('range i ', 0)
('if i', 4)
('range i ', 1)
('if i', 5)
('range i ', 2)
('if i', 6)
('range i ', 3)
('if i', 7)
('range i ', 4)
('if i', 8)
('range i ', 5)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…