Skip to content
Justice Tech School

while Loops, break and continue

while repeats while the condition is true. break exits, continue skips and else runs if the loop was not broken.

Example
i = 0
while i < 6:
    i += 1
    if i == 2:
        continue
    if i == 5:
        break
    print(i)
else:
    print("no break")

Result

1
3
4

Exercise

Skip an iteration.

Quiz Test

When does while-else run?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.