The break is a one-line statement that means “exit the current loop.” An alternate way to make our counting loop exit and stop executing is with the break statement.

  • First, create a while with a condition that is always true. The simplest way is shown.

  • Using an if statement, you define the stopping condition. Inside the if, you write break, meaning “exit the loop.”

The difference here is that this loop is guaranteed to run at least once.



See what the break does? Feel free to mess around with it (but make sure you don’t cause an infinite loop)! Click Run when you’re ready to continue.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?