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 trialayesha mirza
1,674 Pointsloop problem
how to use 'continue' in proper way
def loopy(items):
# Code goes here
if item in items.index[0]='a':
continue
else:
print(item)
2 Answers
Josue Ipina
19,212 PointsThe for loop and the if conditional should be separate. Start the for loop, to iterate through items. Then, inside the loop, use the if conditional to continue if the first letter in item is equal to 'a'; otherwise, print the item:
def loopy(items):
# Code goes here
for item in items:
if item[0] == 'a':
continue
else:
print(item)
Daniel Turato
Java Web Development Techdegree Graduate 30,124 PointsYour code actually works but a much easier way of doing this would be to do something like this.
def loopy(items):
for item in items:
if item == 'a':
continue
else:
print(item)
Continue is used to basically miss the rest of the loop and restart again at the start of the loop. So in your code, if the item in the list items is equal to 'a', the loop will restart and the list item will be incremented. This should in theory print out all items in the list unless the very first item is equal to 'a'. Hope this helps.