Practice: continue Statement
Q1. Skip the number 3
Print the numbers 1 to 5 but skip 3 using continue.
Goal: Use continue to skip one value.
Q2. Print only positives
Given [3, -1, 4, -5, 9], print only the positive numbers.
Goal: Filter data with continue.
Q3. Skip short words
Print only words from ["a", "python", "is", "great"] that have more than 2 letters.
Goal: Filter by length.
Q4. Sum without multiples of 3
Add the numbers from 1 to 10, skipping multiples of 3. Print the total.
Goal: Accumulate with filtering.
Q5. While loop with continue
Print 1 to 6 with a while loop, skipping 4. Be careful with the counter.
Goal: Use continue safely in while.
Q6. Count valid entries
From the list ["5", "x", "7", "", "2"], add up only the entries that are digits using isdigit() and continue. Print the sum.
Goal: Use guard clauses for validation.
Q7. Skip in a for loop
What does this code print?
for i in range(4):
if i == 2:
continue
print(i)Goal: Trace continue.
Q8. Continue versus break
What does this code print?
for i in range(5):
if i == 2:
break
print(i)Goal: Compare with break.
Q9. Nested continue
What does this code print?
for a in range(2):
for b in range(3):
if b == 1:
continue
print(a, b)Goal: Know the scope of continue.
Q10. Loop else with continue
What does this code print?
for n in [1, 2, 3]:
if n == 2:
continue
print(n)
else:
print("done")Goal: Combine continue and else.
Q11. Counting with continue
What does this code print?
count = 0
for ch in "banana":
if ch == "a":
continue
count += 1
print(count)Goal: Trace string iteration.
Q12. Infinite loop with continue
This loop never ends. Fix it so it prints 1, 2, 4, 5.
i = 0
while i < 5:
if i == 2:
continue
i += 1
print(i)Goal: Avoid the counter trap.
Q13. Wrong statement
This code should print all numbers from 1 to 5 except 3, but it stops at 2. Fix it.
for n in range(1, 6):
if n == 3:
break
print(n)Goal: Choose between break and continue.
Q14. What does continue do?
Explain in one sentence what continue does.
Goal: Define continue.
Q15. What happens after continue in while?
After continue runs in a while loop, what does Python do next?
Goal: Understand while behaviour.
Q16. Ignore comment lines
Given the lines ["# note", "x = 1", "# todo", "y = 2"], print only the lines that do not start with #.
Goal: Apply continue to text processing.