continueExpert Examples

Skips the rest of the current loop iteration and moves to the next

Continue bytecode

How continue compiles compared to break.

python
import dis

def with_continue():
    for i in range(10):
        if i % 2 == 0:
            continue
        print(i)

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

print("continue bytecode:")
dis.dis(with_continue)
print("\nbreak bytecode (for comparison):")
dis.dis(with_break)

# continue jumps to the top of the loop (FOR_ITER)
# break jumps past the loop entirely

continue compiles to a JUMP_ABSOLUTE back to the FOR_ITER instruction at the top of the loop, while break jumps past the loop. Both are simple unconditional jumps.

Want to try these examples interactively?

Open Expert Playground