Codecademy Forums

How does break work? [solved]

Hi , i used this code but i do not know why it is not working . And also i read the solution and i did not understand how , like they did not mention if we should move by one or two after removing the even number ? Can someone explain please ! Thnak you .

![coding2|513x250]

break will terminate the loop, which means only one even number is found. Might need to rethink this and try again.

Iterate over the list one element at a time until an odd number is reached.

1 Like

Oh yeah u are right !! And concerning the solution , why they put lst [1 : ] ? they did not mention how much we should move to verify again the other index .coding2

There are usually a variety of possible solutions. In this course we are not looking for the cleverest, but the one that shows an understanding of core fundamentals such as functions, loops, and data structures, along with a few of their methods.

Consequently the author of the lesson could not consider every solution, or how to guide us toward one. It is a challenge for which we have enough tools to complete the task, however inelegant or naive.

From the get-go we need to take our bearings and understand the objective: The list must not begin with an even number when we return it.

Does that mean we should physically delete even numbers from the list? Is there a simple way to find the first odd number in the list and obtain its index? Let’s take a naive approach, first, and then whittle it down with logic…

for i in range(len(lst)):
    if lst[i] % 2: return lst[i:]
return []

Turns out there wasn’t that much logic required, and we didn’t have to perform any manipulation of the list, only return the portion that started with an odd number. If there are no odd numbers, then return an empty list.