Can't figure out how to use break properly on coding challenge in python
def loopy(items): for word in items: print(word) if items == "STOP": break
I've tried replacing word with items and moving the if statement to the same indentation as for.
Brandon OakesPython Web Development Techdegree Student 11,500 Points
So it looks like your function is taking one argument(items), which I am assuming is a list. Then you have a for loop that is taking each element(word) in the list and is printing that element(word). Why don't you incorporate a if/else statement. You just have a if statement.
for word in items: if word == "STOP": break else: print(word)
the if/else statements will allow you to tell python "hey do this IF this is true, ELSE always do something else". Also in your code, you are looping through a list to look at WORD but you are telling python to break if ITEMS== "STOP".