Python — From Basics to Advanced · Flow Control
The while Loop
Flow Control
Introduction
while repeats a block of code as long as the condition is true. You will learn when to choose while over for, how to avoid infinite loops, use a sentinel/while True + break, and handle counters without off-by-one bugs.