break Exits the Loop

Are you done with the read_int exercise? I imagine you could've written something like this:

and if so, great job! You could have written a longer version too, and it's completely fine. Something like this will work:

This is the second time we write a while loop this way:

The finished variable gets eventually assigned to 1 inside the loop, and the loop ends after that.

There is an easier way to do the same thing: the break instruction. break; means "exit the loop right now". Here I'll use while (1), which is an infinite loop – or, better to say, it would've been an infinite loop if I hadn't used break inside:

Since break exits the loop, it sometimes makes sense to check the exit condition first:

But break is useful not only for would-be-infinite loops, but for regular loops as well. Let's look at the example on the next page!