A stopping criterion is a condition that tells a program when to stop repeating instructions or choose a different execution path. In a loop, the program checks the condition again after each pass; repetition ends when the condition becomes false. section 14.0 section 18.1
Guessing until the answer is correct
secret = "code" guess = input("Guess a word: ") while guess != secret: print("Try again") guess = input("Guess again: ") print("You got it!") The test guess != secret is the stopping criterion. A wrong guess keeps the loop running; the correct guess makes the condition false, so execution continues after the loop. section 18.1
A useful stopping criterion should make the intended endpoint clear:
- Check whether repetition is still needed, rather than instructing the computer to repeat forever. section 16.1
- Change something related to the condition inside the loop; otherwise, the program can enter an infinite loop. section 18.1
- Use several conditions when a decision depends on more than one requirement, such as price range and phone color. section 14.0










