Let's suppose I have a list of 1000 values, however, I am not interested in values between 111 and 889. Is there a way in python to entirely skip iterations of a for loop without using continue to reduce time complexity? It seems like a waste to run the for loop 1000 times when I only need to run it 222 times.
l = [1,2,3,111,5,6,7,8,9,889,12,2,111,4,5,6,889]
for i in l:
if i == 111:
// skip to 889
else:
// do stuff
There could be multiple occurrences of 111 and 889 in this list and all the values in between should be skipped. If there is no 889 after 111 the for loop should end