githubEdit

Break and Continue Statements

Use break to exit a loop early. Use continue to skip the rest of the current iteration and move to the next.

break

for letter in "Python":
    if letter == "h":
        break
    print(letter)

Output:

P
y
t

continue

for letter in "Python":
    if letter == "h":
        continue
    print(letter)

Output:

P
y
t
o
n

Common Pitfalls

  • Using break when you meant return inside a function.

  • Using continue and accidentally skipping necessary updates.

Previous

Last updated