Use break when a loop should stop after a condition becomes true. A common pattern is while True, which creates an infinite loop, followed by input, processing, and a conditional break when the task is complete. break exits the innermost enclosing loop. section 2.3 section 5.9
When applying this pattern, keep the termination path explicit:
- Begin an intentional infinite loop with while True. section 2.3
- Read and convert input when the comparison requires matching types; input returns a string, while numeric comparisons require an integer. section 2.3
- Place break in the success condition, such as a correct guess or the end of data entry. section 2.3 section 5.9
Two interactive loops
A number-guessing exercise repeats prompts until the user correctly guesses the randomly selected answer, then uses break to leave the loop. A rainfall tracker similarly gathers city names and amounts inside while True and stops only when break is encountered. section 2.3 section 5.9






