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 Collections (2016, retired 2019) Sets Out Of This Word Game

What does "break" in while loop in this code?

Hi,

I wonder how the statement "break" does in while loop. My guess is when we run the code, "player1_word = prompt_for_words(challenge_word)" is run first. Under running when the user prompt "break" then does the code go to "player2_word = prompt_for_words(challenge_word)"? I thought "break" does to continue executing the next step after while loop which is the part "guesses.add(guess.lower()) return guesses" but it seems I am wrong. Now I am confused the logic of "break" usage in coding. Could you please help me with this?

1 Answer

Steven Parker
Steven Parker
229,967 Points

Your description sounds correct. A "break" will cause a loop to end, and execution will immediately move to the first statement after the loop.

What was it that caused you to think this might not be the case?