Control Flow

Break and Continue

break exits a loop early, while continue skips to the next iteration.

continue skips the rest of the current iteration. The empty name is ignored, and the loop moves on to the next value.

Source

names = ["Ada", "", "Grace"]
for name in names:
    if not name:
        continue
    print(name)

Output

Ada
Grace
abcdefound · breakfirst match
break exits the loop; continue skips to the next iteration. Both interrupt the natural fall-through.

break exits the loop immediately. The value after stop is never processed because the loop has already ended.

Source

commands = ["load", "save", "stop", "delete"]
for command in commands:
    if command == "stop":
        break
    print(command)

Output

load
save

Notes

See also

Run the complete example

Example code

Expected output

Ada
Grace
load
save

Execution time appears here after you run the example.