Search⌘ K
AI Features

Challenge: Break the Loop

Explore how to create while loops that keep running based on user input, using break to stop loops and continue to skip iterations. Gain practical experience in controlling program flow by building a loop that interacts with user input until a specific word is entered.

We'll cover the following...

Sometimes you want a program to keep running until the user decides to stop.

Python can do this using a while loop that runs forever, and then stopping it manually using special keywords.

Two important tools you’ll use here are:

  • break → stops the loop completely

  • continue → skips the rest of the loop and starts again

Your task:

  1. Create a loop that keeps asking the user to type a word

  2. If the user types "bye", stop the loop

  3. If the user presses Enter without typing anything, skip that input

  4. Otherwise, print what the user typed

💡 Things to keep in mind:

  • A while loop can run forever unless you stop it

  • break ends the loop

  • continue skips to the next loop cycle

  • You only need one loop

When you click Run, your program should keep responding until the user types "bye".

# Write your code here.
Asking for words, skipping blanks, and stopping at “bye”