A while loop is very similar to a for loop. It simply continues to do something while a given condition is true. We typically use while loops when we are unsure about how many times we may possibly be looping (or repeating something). The syntax looks something like this:
Breaking a Loop
Sometimes while we are looping we may encounter a situation where we want to exit the loop. It may be the case that the condition keeping the loop running is still True but we would still like to "break" the loop. We can do this using the "break" keyword.
Whenever we encounter the word "break" within a loop (for or while) we will immediately exit that loop.
Here is a common example of when we would use a while loop: