STEP 10: Let's make our loop stop if the user guessed correctly. To do that we'll use a break statement.

The break keyword tells our program to stop running the loop if it reaches that line of code. The line of code will have a purple and yellow ········ block in front of it to show that it is nested twice.

  • Change the string in .say() to "Great job, you guessed my number!"
  • In LOGIC, in drag out Break. Drop it at the bottom of your program, INSIDE the if-statement.

To navigate the page using the TAB key, first press ESC to exit the code editor.

# THIS ACTIVITY IS IN PREVIEW ONLY MODE
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)