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

Daniel McFarlin
Daniel McFarlin
5,168 Points

Coding challenge involving skipping a word according to it's "0" index? I don't remember seeing this covered at all

Hey I honestly don't know where this was covered in the videos, but I have no idea where to begin to get this code working. Any help on this one would be much appreciated!

Thank you!

1 Answer

Hello! This is one way that issue could be solved. If you have any trouble reading this code and understanding it let me know. Much better to grasp the concept than just move forward :)

def loopy(items):
    # Code goes here
    for item in items:
        if item[0] == "a":
            continue
        else:
            print(item)
Daniel McFarlin
Daniel McFarlin
5,168 Points

Thanks Samuel! The only part that still is not sure in my mind when it comes to this code is when "continue" is necessary and when it isn't. I remember Kenneth trying to explain that, but I didn't completely follow what he was saying. Could you explain to me as well? That would be awesome if you can! If not, thank you so much for the help you have given me already :)

Stuart Wright
Stuart Wright
41,118 Points

To answer your question about 'continue', it has the effect of moving on to the next item in your loop.

So in this case you have a list of items, and if the first letter of any item = a, you continue on to the next item in the loop. This means that even if there was additional code after the else block (but still inside the for loop), it would not be executed if the first letter of the current item = a.

If you had some code after the else block that you wanted to execute regardless of whether or not the first letter of current item = a, you would use 'pass' in place of 'continue'. While 'continue' jumps straight to the next item in the loop, 'pass' just does nothing.