What type of loop repeats code as long as a condition is true?
Answer
while loop
Answer
while loop
A while loop repeats code as long as a condition is true. Python checks the condition before each iteration, so if it is false at the start, the loop body runs zero times.
The condition is normally changed inside the loop so execution can eventually stop. For example, `while count < 3:` can increment `count` on each pass. If the condition never becomes false—or the loop uses `while True` without a `break`—the program enters an infinite loop.
A common mix-up is the for loop, which is generally used to iterate over items in a sequence or other iterable. A do-while loop, available in languages such as C and Java, checks its condition after the body and therefore runs at least once; Python has no built-in do-while keyword. Python programmers can approximate that behavior with `while True` and a conditional `break`.
Source: Wikipedia · fact-checked Aug. 2026