Courses/Control Flow

๐Ÿ”€ Control Flow

while loops

Loop until a condition becomes false.

Use while when you don't know in advance how many iterations you need.

n = 1
while n < 100:
    n *= 2
print(n)  # 128

Always make sure the condition will eventually become false โ€” otherwise infinite loop!

main.py
Output
Press Run to execute.
Expected output
128

Sign in to track your progress across lessons.