FAQ: Learn Python: Loops - Break


#1

This community-built FAQ covers the “Break” exercise from the lesson “Learn Python: Loops”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Computer Science
Data Science

FAQs on the exercise Break

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


#2
dog_breeds_available_for_adoption = ['french_bulldog', 'dalmation', 'shihtzu', 'poodle', 'collie']
dog_breed_I_want = 'dalmation'

for adoption in dog_breeds_available_for_adoption:
  ######## This is for Problem 1 ########
  # You have a list of dog breeds[dog_breeds_available_for_adoption] you can adopt[adoption]
  print(adoption)
  # list and print out each dog breed.  Remember, adoption is representing each dog available for adoption.
  # You do not want to print out dog_breeds_available_for_adoption as it will print the list, not the loop.
  ######## This is for Problem 2 ########
  if adoption == dog_breed_I_want:
  # check if (if) it is equal (==) to dog_breed_I_want.  If so, print (print) "They have the dog I want!"
  # This should be very straight forward. again, adoption rep all the breeds in the list.  
  # So it compares the list of breeds to the dog you want.
    print("They have the dog I want!")
  ######## This is for Problem 3 ########
    break
  # This essentially will pump the breaks on the code not to look any further.
  # So it will print all the breeds before it until it gets to the one you want then prints.