KIIT Polytechnic logo Students Hub KIIT Polytechnic Sign in
▲The Board ◆Notes ≡Syllabus ▦Timetable ?Doubts ▶Reels 🎮Learn 🐍Courses ◈Opportunities ✍Blog ▮Store ★Team ⌕Search
← Learn to Code — Python for Beginners Module · 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.