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

Jt Miller
Jt Miller
1,242 Points

Confused on challenge

This is what it tells me to do and i have 0 clue what it is trying to tell me.

Same idea as the last one. My loopy function needs to skip an item this time, though. Loop through each item in items again. If the character at index 0 of the current item is the letter "a", continue to the next one. Otherwise, print out the current member. Example: ["abc", "xyz"] will just print "xyz".

breaks.py
def loopy(items):
    # Code goes here

1 Answer

Rich Zimmerman
Rich Zimmerman
24,063 Points

Take it step by step. you know you want to loop through the items... within the loop you want to check what the character is at index 0 (the first character in the string), and if it is "a", skip it... otherwise print it

def loopy(items):
    # loop through the items
    for item in items:
        # check the character at index 0 and skip it if its 'a'
        if item[0] == 'a':
            continue
        else:
            # else print item
            print(item)
Jt Miller
Jt Miller
1,242 Points

Ok thank you makes sense still kinda lost on the continue function but the rest is clear

Rich Zimmerman
Rich Zimmerman
24,063 Points

"continue" in loops basically skips the remainder of the code block and goes to the next iteration of the loops.

For example, say we want to loop through the numbers 1-5 and print out everything but the number 4.

for i in range(1,6):
    if i == 4:
        # at this point if i ==4, it will skip the "print(i)" line and go to the next 
        # iteration of the loop, where i == 5
        continue     
    print(i)