Codecademy Forums

Infinite loop [solved]

Hi, running the given code makes my compiler go in the infinite loop mode. Why ?
Please Help!

#Write your function here
def delete_starting_evens(lst):
  index= 0
  if(len(lst) == 0) or (lst[0] % 2 != 0):
    return lst
    for num in lst:
      while(num % 2 == 0):
        index += 1
    lst = lst[index+1:]
    return lst

#Uncomment the lines below when your function is done
print(delete_starting_evens([4, 8, 10, 11, 12, 15]))

inside the while loop, num never changes, thus the while loop will run infinitely

why use a while loop there anyway? You already have a loop, inside the loop you can use an if condition to check if index needs increasing.

1 Like

Got it! Thanks! Rectification done too!