Bird
Raised Fist0
Pythonprogramming~20 mins

Break vs continue execution difference in Python - Practice Questions

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
🎖️
Loop Control Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of break in a loop
What is the output of this Python code using break inside a loop?
Python
for i in range(5):
    if i == 3:
        break
    print(i)
A
0
1
2
3
4
B
1
2
3
C
0
1
2
3
D
0
1
2
Attempts:
2 left
💡 Hint
Remember, break stops the loop immediately when the condition is met.
Predict Output
intermediate
2:00remaining
Output of continue in a loop
What is the output of this Python code using continue inside a loop?
Python
for i in range(5):
    if i == 3:
        continue
    print(i)
A
0
1
2
4
B
0
1
2
3
4
C
0
1
2
3
D
1
2
3
4
Attempts:
2 left
💡 Hint
Think about what continue does: it skips the current loop iteration.
🧠 Conceptual
advanced
1:30remaining
Difference between break and continue
Which statement correctly describes the difference between break and continue in loops?
A<code>break</code> and <code>continue</code> both exit the loop immediately.
B<code>break</code> exits the entire loop; <code>continue</code> skips to the next iteration.
C<code>break</code> skips the current iteration; <code>continue</code> exits the loop.
D<code>break</code> pauses the loop; <code>continue</code> restarts the loop from the beginning.
Attempts:
2 left
💡 Hint
Think about what happens to the loop after each keyword is executed.
Predict Output
advanced
2:00remaining
Loop behavior with break and continue combined
What is the output of this code that uses both break and continue?
Python
for i in range(6):
    if i == 2:
        continue
    if i == 4:
        break
    print(i)
A
0
1
3
B
0
1
2
3
C
0
1
3
4
D
0
1
2
3
4
Attempts:
2 left
💡 Hint
Check the order of conditions and what each keyword does.
🧠 Conceptual
expert
2:30remaining
Effect of break and continue in nested loops
In nested loops, which statement is true about break and continue?
A<code>break</code> exits all loops; <code>continue</code> skips all remaining iterations of all loops.
B<code>break</code> and <code>continue</code> affect only the outermost loop.
C<code>break</code> exits only the innermost loop; <code>continue</code> skips to the next iteration of the innermost loop.
D<code>break</code> skips the current iteration of the outer loop; <code>continue</code> exits the inner loop.
Attempts:
2 left
💡 Hint
Think about which loop the keywords apply to when loops are inside each other.

Practice

(1/5)
1. What does the break statement do inside a loop in Python?
easy
A. Stops the entire loop immediately
B. Skips the current iteration and continues with the next
C. Ends the current function
D. Restarts the loop from the beginning

Solution

  1. Step 1: Understand the role of break

    The break statement is used to exit a loop completely when a condition is met.
  2. Step 2: Compare with other options

    Unlike continue, which skips one iteration, break stops the loop entirely.
  3. Final Answer:

    Stops the entire loop immediately -> Option A
  4. Quick Check:

    break = stop loop [OK]
Hint: Break stops loop; continue skips iteration [OK]
Common Mistakes:
  • Confusing break with continue
  • Thinking break skips only one iteration
  • Assuming break restarts the loop
2. Which of the following is the correct syntax to skip the current iteration in a loop?
easy
A. skip
B. break
C. continue
D. stop

Solution

  1. Step 1: Identify the keyword to skip iteration

    The keyword continue is used to skip the current iteration and move to the next one.
  2. Step 2: Check other options for correctness

    break stops the loop, while skip and stop are not valid Python keywords.
  3. Final Answer:

    continue -> Option C
  4. Quick Check:

    continue skips iteration [OK]
Hint: Use continue to skip iteration, break to stop loop [OK]
Common Mistakes:
  • Using break instead of continue
  • Using non-existent keywords like skip
  • Confusing syntax for loop control
3. What is the output of the following code?
for i in range(5):
    if i == 3:
        break
    print(i)
medium
A. 0 1 2 3
B. 0 1 2 3 4
C. 3 4
D. 0 1 2

Solution

  1. Step 1: Analyze the loop and break condition

    The loop runs from 0 to 4. When i == 3, the break stops the loop immediately.
  2. Step 2: Determine printed values before break

    Values 0, 1, and 2 are printed. When i reaches 3, loop stops before printing 3.
  3. Final Answer:

    0 1 2 -> Option D
  4. Quick Check:

    break stops loop at 3, prints before it [OK]
Hint: Break stops loop before printing current value [OK]
Common Mistakes:
  • Including the break value in output
  • Confusing break with continue
  • Assuming loop runs fully
4. Find the error in this code snippet:
for i in range(4):
    if i == 2:
        continue
    print(i)
    break
medium
A. The break is inside the loop and will stop after first iteration
B. continue is used incorrectly and causes syntax error
C. The loop will never run because of break before print
D. No error, code runs and prints 0, 1, 3

Solution

  1. Step 1: Understand loop flow with continue and break

    When i == 2, continue skips print and break for that iteration. For other values, print runs then break stops loop immediately.
  2. Step 2: Identify effect of break placement

    Break inside the loop after print causes loop to stop after first printed value, so only one value prints.
  3. Final Answer:

    The break is inside the loop and will stop after first iteration -> Option A
  4. Quick Check:

    Break stops loop early due to placement [OK]
Hint: Break after print stops loop early, continue skips iteration [OK]
Common Mistakes:
  • Thinking continue causes syntax error
  • Assuming loop prints all values
  • Ignoring break effect inside loop
5. You want to print all numbers from 0 to 9 except 5, but stop printing if the number reaches 8. Which code snippet correctly uses break and continue?
hard
A. for i in range(10): if i == 5: break if i == 8: continue print(i)
B. for i in range(10): if i == 5: continue if i == 8: break print(i)
C. for i in range(10): if i == 8: continue if i == 5: break print(i)
D. for i in range(10): if i == 5: continue if i == 8: continue print(i)

Solution

  1. Step 1: Understand requirements for skipping and stopping

    We skip printing 5 (use continue) and stop printing at 8 (use break).
  2. Step 2: Check each option for correct order and logic

    for i in range(10): if i == 5: continue if i == 8: break print(i) correctly continues at 5 to skip it, breaks at 8 to stop loop, and prints others.
  3. Final Answer:

    Option B code snippet -> Option B
  4. Quick Check:

    continue skips 5, break stops at 8 [OK]
Hint: Continue skips unwanted, break stops loop early [OK]
Common Mistakes:
  • Swapping break and continue conditions
  • Using break to skip instead of continue
  • Not stopping loop at 8