Python Loop Control


Python provides three loop control statements to change the flow of loops:

  • break – Exit the loop prematurely

  • continue – Skip the current iteration

  • pass – Do nothing, acts as a placeholder

These can be used inside for or while loops.


🔹 Break Statement

Used to stop the loop immediately, even if the condition is still true.

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

Output:
0 1 2 3 4


🔹 Continue Statement

Used to skip the current iteration and move to the next.

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

Output:
0 1 3 4


🔹 Pass Statement

Used when a statement is required syntactically, but you don’t want to execute any code.

for i in range(3):
    pass

pass is often used as a placeholder in loops, classes, functions, etc.


🔹 Break in While Loop

i = 1

while i <= 5:
    if i == 3:
        break
    print(i)
    i += 1

🔹 Continue in While Loop

i = 0

while i < 5:
    i += 1
    if i == 3:
        continue
    print(i)

🔹 Pass in Loop

numbers = [1, 2, 3, 4]

for n in numbers:
    if n == 3:
        pass
    print(n)

🧪 Try It Yourself

Use break, continue, and pass in both for and while loops to control flow based on conditions.


Practice Questions

Q1. Write a Python program to print numbers from 1 to 10, but stop the loop when the number is 7 using break.

Q2. Write a Python program to print all numbers from 1 to 10, but skip the number 5 using continue.

Q3. Write a Python program using a while loop and break the loop when the number equals 4.

Q4. Write a Python program to use continue to skip even numbers from 1 to 10 and print only odd numbers.

Q5. Write a Python program to create a loop that prints numbers from 1 to 5 and use pass inside the loop.

Q6. Write a Python program to print only the vowels from the string "PythonLoopControl" using a loop.

Q7. Write a Python program to loop through numbers from 1 to 20 and break at the first number divisible by 9.

Q8. Write a Python program to loop through numbers from 1 to 10 and skip numbers divisible by 3 using continue.

Q9. Write a Python program to use pass to handle a missing condition in a loop (e.g., as a placeholder for future logic).

Q10. Write a Python program to build a login system that keeps asking for a password and breaks the loop when the correct password is entered.


Python Loop Control Quiz

Q1: What does break do in a loop?

A. Skips current iteration
B. Exits the loop
C. Restarts the loop
D. Prints error

Q2: What does continue do?

A. Stops loop
B. Ends program
C. Skips current loop iteration
D. Jumps to end of code

Q3: What is the purpose of pass?

A. Stops loop
B. Placeholder for future code
C. Skips value
D. Makes loop faster

Q4: Which statement does nothing when executed?

A. continue
B. pass
C. break
D. stop

Q5: What happens after continue is executed in a loop?

A. Loop ends
B. Loop restarts
C. Next iteration begins
D. Error

Q6: Where can you use break?

A. Only in if statements
B. In loops
C. Only in functions
D. Only in for loop

Q7: What is printed by this code: for i in range(5): if i==2: break; print(i)?

A. 0 1
B. 0 1 2
C. 2 3 4
D. 0 1 3 4

Q8: What is printed if continue is used when i == 2 in a loop from 0–4?

A. 0 1 2 3 4
B. 0 1 3 4
C. 0 1 2
D. Nothing

Q9: Can pass be used inside a loop without error?

A. No
B. Yes
C. Only with break
D. Only with while loop

Q10: What does this code do: for i in range(5): pass?

A. Prints 0 to 4
B. Skips all values
C. Runs silently without output
D. Error

Go Back Top