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
First, create a
whilewith a condition that is always true. The simplest way is shown.
ifstatement, 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.