while Loop in Python
while checks a condition first, then runs the body, then checks again. while i <= 3: print(i); i += 1. If you forget i += 1, it never ends. If i starts at 10 and the condition is i <= 3, the body runs zero times. That “maybe zero” fact is an MCQ favourite.
Use while when you don’t know the count: read lines until empty, retry until success. for is cleaner when you already have a list. Contrast them in one sentence each.
while Loop in Python — output — 1 then 2 then 3. When i becomes 4, loop stops.
i = 1
│ i <= 3 ?
▼ yes
print(i); i += 1
│
▼ i = 4 → stopCounter while i <= 3 + what if i starts too big.