An infinite loop keeps running because its condition remains true. In Python, while True creates this pattern; break must provide an explicit exit, usually after the desired input or result appears. section 1.3 section 4.9
Use an infinite loop when a program should continue accepting attempts until a meaningful stopping condition occurs:
- A number-guessing program repeatedly requests guesses and breaks when the converted integer equals the randomly selected answer. section 1.3
- A rainfall collector repeatedly reads city names and measurements, updating a dictionary until control flow exits the loop. section 4.9
- Place validation inside the loop: invalid rainfall input prints an error and continue starts the next iteration. section 4.9
A loop that waits for a correct guess
Generate an answer with random.randint, then run while True. Convert input from its returned string form with int(...), compare the integer with answer, and use break when the guess is correct. Without that break, the loop has no exit. section 1.3


