 Here's a flowchart of a while loop. It starts by testing a condition. When the condition is true, we do the body of the loop and then return to test the condition. As long as it's true, we do the loop body and return to test the condition again. When the condition is false, the loop has concluded. Here's the generic form in Python. It starts with the keyword while, the condition you want to test, and a colon. The loop body is indented underneath the while. Here's a program that we want to write using a while statement. We want to find the value of N for which the sum of squares up to and including N is greater than or equal to 100. And here's our flowchart. We'll start by setting N and the sum of squares to zero. We'll test if the sum of squares is less than 100. If it is, we have to add one to N, add N squared to the sum, and to see how it's progressing, we'll print them both. We loop back to the condition. Eventually, the sum of squares will not be less than 100. We will have achieved our goal and we can print the answer. Here's the Python program. We'll initialize our variables, N will become zero, and the sum of squares will become zero. Now we have our while, and the condition we're testing is whether the sum of squares is less than 100. If that's true, we'll do the body of the loop. We'll add one to N, and we'll add N squared to the sum of squares and print their current values. I'm putting this in here to show that the loop is really proceeding. Once the body of the loop is done, we'll come back and test this condition again. Eventually, the sum of squares will not be less than 100. The loop will conclude, and we will print N and the sum of squares properly labeled with their final values. And let's run the program. And there we see our output that tells us that the sum of the squares of the numbers 1 up to 7 gets us above the limit of 100. When using a while loop, you usually don't know in advance how many times the loop will repeat. Let's look at another use of while, getting input until the user tells us they're finished. Here's a program that asks users to enter prices of items and gives them a total when they've finished. This is another instance where we don't know how many times the loop will repeat. We don't know how many items the customer has. They may have one item, ten items, or fifty items. So this is an ideal place for a while loop. The question then becomes, how does the user tell us when they have finished entering prices? We're going to use a sentinel value, a special value that indicates that there are no more data items coming in. In this case, we'll use zero as the price, because nothing in the store is free. That'll be our sentinel value. We start by setting the total to zero. And we set a Boolean variable, more input, and start it initially as true, meaning yes, I'm waiting for more input. I'm going to run the program so I can do the narrative along with the code. Because I'm waiting for more input, that's true, I do the body of the loop. And that is why we see the prompt to enter the price. I'm going to enter eight dollars. Eight dollars is not equal to zero, which means that eight dollars will be added to the total, and that's the end of our loop body. We come back and ask, are we waiting for more input? It's still true, we haven't changed that value. And that's why I got the prompt again, to enter the price or zero to finish. This time I'll add four dollars and fifty cents. Again, four dollars and fifty cents isn't zero. It'll get added into our total. That's the end of our loop body, and we'll say is more input true? Yes, we're still waiting for more input. And that's why, again, I'm going to get my prompt. This time I'm going to enter that zero, the sentinel value. Zero is not equal to zero is false. Zero is equal to zero. That means we'll take the else branch and set more input to false, saying we don't want more input. We're at the end of our loop body. We come back and test the condition. Now more input is false, which means the loop is done, and we drop out of the loop and proceed to the last line in the program, where we see our total. And that's what you can do with a while loop, a loop that repeats some actions as long as some condition is true. You don't need to know the exact number of iterations in advance.