← Learn to Code — Python for Beginners
मॉड्यूल · Repeating Yourself
while loops
A for loop repeats a known number of times. A while loop repeats until a condition becomes false — useful when you don't know in advance how many times you'll need to repeat.
count = 0
while count < 5:
print(count)
count = count + 1
Be careful: if the condition never becomes false, the loop runs forever (an "infinite loop"). Always make sure something inside the loop eventually changes the condition.