Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Shopping List App Continue

Akhil Dogra
Akhil Dogra
444 Points

could not continue

I am unable to use the concept of break and continue in tthe given question

breaks.py
def loopy(items):
    # Code goes here
    for item in items:
        if items.index(0)=='a':
        break
        continue
        print(item)
        else:
        print(item)

2 Answers

Alex Trost
Alex Trost
6,270 Points

Pasting the challenge text to refer to: "Same idea as the last one. My loopy function needs to skip an item this time, though. Loop through every item in items. If the current item's index 0 is the letter "a", continue to the next one. Otherwise, print out the current member."

This one took me a minute, too. I had to walk away and come back to understand that "If the current item's index 0 is the letter "a"" just means: "Does the word in the list start with the letter 'a'?"

So if you have

items=['apple', 'banana','lemon', 'lime', 'avocado', 'apricot', 'watermelon']

Then your code needs to print: banana lemon lime watermelon

Steven is right, you need to indent after your if and else statements to tell python that those statements belong to that if/else statement.

Like he said, get rid of the 'break': That's going to break out of your loop right away,(in this case, ending your program, as you have no more code) when you want to "continue to the next one).

The first print(item) would never be used, even if you indented properly, because it's after a break (which should be removed) as well as a continue (which will send the program back to the next item in items, starting the loop over).

The second print function should work just fine. Good luck, you're 95% there!

Steven Parker
Steven Parker
231,007 Points

Check your indentation, any action associated with the if must be indented another level in. And you won't need to use break.

Also, items.index(0) looks for the index of an item that contains 0. But you want the value of the item with the 0 index, that would just be 'items[0]'.

Akhil Dogra
Akhil Dogra
444 Points

I corrected my indentation and removed the break instruction and used the proper format for the list but still unable to achieve the process def loopy(items): for item in items: if items[0]=='a': continue print(item)