Practice: continue Statement

« Read the chapter

Q1. Skip the number 3

BeginnerCoding

Print the numbers 1 to 5 but skip 3 using continue.

Goal: Use continue to skip one value.

Q2. Print only positives

BeginnerCoding

Given [3, -1, 4, -5, 9], print only the positive numbers.

Goal: Filter data with continue.

Q3. Skip short words

BeginnerCoding

Print only words from ["a", "python", "is", "great"] that have more than 2 letters.

Goal: Filter by length.

Q4. Sum without multiples of 3

IntermediateCoding

Add the numbers from 1 to 10, skipping multiples of 3. Print the total.

Goal: Accumulate with filtering.

Q5. While loop with continue

IntermediateCoding

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

AdvancedCoding

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

BeginnerOutput

What does this code print?

Code
for i in range(4):
    if i == 2:
        continue
    print(i)

Goal: Trace continue.

Q8. Continue versus break

BeginnerOutput

What does this code print?

Code
for i in range(5):
    if i == 2:
        break
    print(i)

Goal: Compare with break.

Q9. Nested continue

IntermediateOutput

What does this code print?

Code
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

IntermediateOutput

What does this code print?

Code
for n in [1, 2, 3]:
    if n == 2:
        continue
    print(n)
else:
    print("done")

Goal: Combine continue and else.

Q11. Counting with continue

AdvancedOutput

What does this code print?

Code
count = 0
for ch in "banana":
    if ch == "a":
        continue
    count += 1
print(count)

Goal: Trace string iteration.

Q12. Infinite loop with continue

IntermediateDebugging

This loop never ends. Fix it so it prints 1, 2, 4, 5.

Code
i = 0
while i < 5:
    if i == 2:
        continue
    i += 1
    print(i)

Goal: Avoid the counter trap.

Q13. Wrong statement

BeginnerDebugging

This code should print all numbers from 1 to 5 except 3, but it stops at 2. Fix it.

Code
for n in range(1, 6):
    if n == 3:
        break
    print(n)

Goal: Choose between break and continue.

Q14. What does continue do?

BeginnerConceptual

Explain in one sentence what continue does.

Goal: Define continue.

Q15. What happens after continue in while?

IntermediateConceptual

After continue runs in a while loop, what does Python do next?

Goal: Understand while behaviour.

Q16. Ignore comment lines

IntermediateApplication

Given the lines ["# note", "x = 1", "# todo", "y = 2"], print only the lines that do not start with #.

Goal: Apply continue to text processing.