Python Learning Series · @onlysamarrr · Day 11 / 30

Day 11: while Loop, break, continue

Day 11 teaches the while loop, break and continue. A while loop runs while its condition is True, break stops the loop immediately, and continue skips the current round and moves to the next one.

Phase: Beginner · Reels: 51/450 – 55/450

Quick Answer

Day 11 teaches the while loop, break and continue. A while loop runs while its condition is True, break stops the loop immediately, and continue skips the current round and moves to the next one.

What You Will Learn

Code

count = 0
while count < 3:
    print("count:", count)
    count += 1
for n in range(1, 10):
    if n % 2 == 0:
        continue
    if n > 5:
        break
    print(n, end=" ")
print()

Output

count: 0
count: 1
count: 2
1 3 5 

Code Explained, Line by Line

  1. while count < 3 keeps looping until count reaches 3.
  2. count += 1 changes the counter each round. Without it the loop would never stop.
  3. continue skips the current round, for example skipping even numbers.
  4. break exits the loop completely as soon as it is reached.
  5. Use for when the count is known; use while when you loop until a condition changes.
Common Mistake: Forgetting to update the loop variable inside a while loop creates an infinite loop: the program never finishes.

Real-Life Use

Retry logic, menus and guessing games use while loops with break and continue.

Practice Task: Write the guessing game logic: if the guess is bigger print 'Too high', if smaller print 'Too low', if equal print 'Correct!' and break.

Test Yourself — MCQs

Select (tick) an option, then tap Check answer to see instantly whether your answer is right or wrong, with an explanation. You can change your answer and check again.

Q1. What does break do inside a loop?

Q2. What does continue do?

Q3. What causes an infinite while loop?

Today's 5 Reels (from the 90-Day Plan Excel)

51/450Conceptwhile loop basics
52/450Live demobreak aur continue demo
53/450Common mistakeInfinite loop galti
54/450QuizQuiz: number guessing
55/450Interview / real lifeInterview: for vs while
← Day 10Day 12 →