Bird
Raised Fist0
Pythonprogramming~20 mins

Continue statement behavior in Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Continue Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of loop with continue inside if
What is the output of this Python code?
for i in range(5):
    if i == 2:
        continue
    print(i, end=' ')
Python
for i in range(5):
    if i == 2:
        continue
    print(i, end=' ')
A1 3 4
B0 1 2 3 4
C0 1 3 4
D0 1 2 3
Attempts:
2 left
💡 Hint
Remember, continue skips the rest of the current loop iteration.
Predict Output
intermediate
2:00remaining
Continue in nested loops
What will be printed by this code?
for i in range(3):
    for j in range(3):
        if j == 1:
            continue
        print(f"{i},{j}", end=' ')
Python
for i in range(3):
    for j in range(3):
        if j == 1:
            continue
        print(f"{i},{j}", end=' ')
A0,0 1,0 2,0
B0,0 0,2 1,0 1,2 2,0 2,2
C0,1 1,1 2,1
D0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2
Attempts:
2 left
💡 Hint
Continue skips printing when j equals 1.
Predict Output
advanced
2:00remaining
Continue with else clause in loop
What is the output of this code?
for i in range(3):
    if i == 1:
        continue
    print(i)
else:
    print('Done')
Python
for i in range(3):
    if i == 1:
        continue
    print(i)
else:
    print('Done')
A
0
2
Done
BDone
C
0
2
D
0
1
2
Done
Attempts:
2 left
💡 Hint
The else block runs after the loop finishes normally.
Predict Output
advanced
2:00remaining
Continue inside while loop
What will this code print?
i = 0
while i < 5:
    i += 1
    if i == 3:
        continue
    print(i, end=' ')
Python
i = 0
while i < 5:
    i += 1
    if i == 3:
        continue
    print(i, end=' ')
A2 3 4 5
B1 2 3 4 5
C1 2
D1 2 4 5
Attempts:
2 left
💡 Hint
Continue skips printing when i is 3.
Predict Output
expert
3:00remaining
Continue with multiple conditions and loop control
What is the output of this code?
result = []
for x in range(1, 6):
    if x % 2 == 0:
        continue
    if x == 5:
        break
    result.append(x)
print(result)
Python
result = []
for x in range(1, 6):
    if x % 2 == 0:
        continue
    if x == 5:
        break
    result.append(x)
print(result)
A[1, 3]
B[1, 3, 5]
C[1, 3, 5, 7]
D[2, 4]
Attempts:
2 left
💡 Hint
Continue skips even numbers, break stops loop at 5.

Practice

(1/5)
1. What does the continue statement do inside a loop in Python?
easy
A. Exits the current function
B. Stops the entire loop immediately
C. Skips the rest of the current loop iteration and moves to the next one
D. Repeats the current iteration without moving forward

Solution

  1. Step 1: Understand the role of continue

    The continue statement tells the loop to skip the remaining code in the current iteration.
  2. Step 2: Identify the loop behavior after continue

    After skipping, the loop moves to the next iteration without stopping the whole loop.
  3. Final Answer:

    Skips the rest of the current loop iteration and moves to the next one -> Option C
  4. Quick Check:

    continue skips current step [OK]
Hint: Remember: continue skips current step, break stops loop [OK]
Common Mistakes:
  • Confusing continue with break
  • Thinking continue exits the function
  • Assuming continue repeats the iteration
2. Which of the following is the correct syntax to use continue inside a for loop?
easy
A. for i in range(5) { continue }
B. for i in range(5): continue
C. for i in range(5) continue
D. for i in range(5): continue

Solution

  1. Step 1: Check Python loop syntax

    Python requires a colon after the for statement and indentation for the loop body.
  2. Step 2: Identify correct placement of continue

    continue must be inside the loop body, properly indented on the next line.
  3. Final Answer:

    for i in range(5):\n continue -> Option D
  4. Quick Check:

    Colon + indent + continue line [OK]
Hint: Use colon and indent for loop body with continue [OK]
Common Mistakes:
  • Missing colon after for statement
  • Writing continue on same line without colon
  • Using braces {} which are not Python syntax
3. What is the output of this code?
for i in range(5):
    if i == 2:
        continue
    print(i)
medium
A. 0 1 3 4
B. 0 1 2 3 4
C. 2
D. 0 1

Solution

  1. Step 1: Trace loop iterations and condition

    The loop runs i from 0 to 4. When i is 2, continue skips printing.
  2. Step 2: List printed values

    Values printed are 0, 1, 3, and 4 because 2 is skipped.
  3. Final Answer:

    0 1 3 4 -> Option A
  4. Quick Check:

    continue skips i=2 print [OK]
Hint: Skip printing when continue triggers, others print [OK]
Common Mistakes:
  • Including 2 in output
  • Thinking continue stops loop
  • Confusing continue with break
4. Find the error in this code snippet:
i = 0
while i < 5:
    if i == 3:
        continue
    print(i)
    i += 1
medium
A. Infinite loop because i is not incremented when i == 3
B. SyntaxError due to missing colon
C. Prints numbers 0 to 4 correctly
D. TypeError because of continue in while loop

Solution

  1. Step 1: Analyze loop and continue effect

    When i equals 3, continue skips the rest, so i += 1 is not executed.
  2. Step 2: Understand consequence

    Since i stays 3 forever, the loop never ends, causing an infinite loop.
  3. Final Answer:

    Infinite loop because i is not incremented when i == 3 -> Option A
  4. Quick Check:

    continue skips i++ causes infinite loop [OK]
Hint: Increment loop variable before continue or use else [OK]
Common Mistakes:
  • Ignoring that continue skips increment
  • Thinking continue causes syntax error
  • Assuming loop ends normally
5. You want to print all numbers from 1 to 10 except multiples of 3 using a for loop and continue. Which code correctly does this?
hard
A. for i in range(1, 11): if i % 3 == 0: pass else: print(i)
B. for i in range(1, 11): if i % 3 == 0: continue print(i)
C. for i in range(1, 11): if i % 3 == 0: break print(i)
D. for i in range(1, 11): if i % 3 != 0: continue print(i)

Solution

  1. Step 1: Understand the goal

    We want to skip printing numbers divisible by 3, so use continue when i % 3 == 0.
  2. Step 2: Check each option

    for i in range(1, 11): if i % 3 == 0: continue print(i) skips multiples of 3 correctly and prints others. for i in range(1, 11): if i % 3 != 0: continue print(i) skips non-multiples wrongly. for i in range(1, 11): if i % 3 == 0: break print(i) breaks loop early. for i in range(1, 11): if i % 3 == 0: pass else: print(i) uses pass but prints all except multiples of 3 correctly but without continue.
  3. Final Answer:

    for i in range(1, 11): if i % 3 == 0: continue print(i) -> Option B
  4. Quick Check:

    continue skips multiples of 3 print others [OK]
Hint: Use continue to skip unwanted cases inside loop [OK]
Common Mistakes:
  • Using break instead of continue
  • Reversing condition logic
  • Not skipping multiples of 3