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 trialPaul Webb
Front End Web Development Techdegree Student 453 Pointsi need help with getting the script to break if "STOP" is found in (items)?
thanks
def loopy(items):
for x in (items):
print(items) #this prints all the variables in (items)
else "STOP" in (items): #not sure the the right way to code this part
break
1 Answer
Paul Webb
Front End Web Development Techdegree Student 453 Pointsok that makes sense, thanks heaps
Brian DuPont
30,448 PointsBrian DuPont
30,448 PointsAlright, so we are passing in a items array into the loopy function. Then the for loop, loops over each variable in the items array and puts the current value into 'x'. So INSIDE of the for loop we need to check for "STOP", using an if statement. If x == STOP then break, else print x (which is the current item in the items array). Hope this helps.