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 trialBrandon Law
559 PointsBreak function
I am working on the breaks.py challenge, and I've been working on it for the last two days but just can't seem to figure it out.
What can I do to fix this? I tried using external sources to help solve it but nothing has worked so far. Thank you!
def loopy(items):
for item in items:
print(item)
if item == "STOP":
break
5 Answers
james south
Front End Web Development Techdegree Graduate 33,271 Pointsyour if block is under the for loop, not in it. it needs to be tabbed over once to be inside. then, i think it wants you to check if the item is stop before printing, so that if it is stop, it doesn't print stop.
Nthulane Makgato
Courses Plus Student 19,602 PointsJame is right.
For the second part:
You have to check that your conditions for "break" are just after the for loop and before you print each item.
Ensure that that BOTH print and "if statement are in the for loop, not outside it. Right now, your if statement is outside the for loop
for item in items:
if item ==...
break
print...
Ellipses dots are for structure, you can fill in the rest.
james south
Front End Web Development Techdegree Graduate 33,271 Points?? that is the second part. are you talking about the next challenge, using the continue keyword? for that one use slice notation with the square brackets [].
Brandon Law
559 PointsThank you guys for the help! It was correct. james south Nthulane Makgato
Nthulane Makgato
Courses Plus Student 19,602 PointsGlad we could help ;)
Brandon Law
559 PointsBrandon Law
559 PointsThank you for your quick reply! james south . How would I go about the second part?