Step 1 · Read and run
Ask again
People type the wrong thing. A while loop can keep asking until the answer makes sense. Checking input like this is called validation.
The pattern is:
- Ask once, before the loop.
- While the answer is no good, say what's wrong and ask again.
- After the loop, the answer is sure to be good.
Run it and try 0, then 12, then 7.
Run the program to carry on.