break and continue
break stops a loop right away. continue skips the rest of the current iteration and jumps to the next value.
code = "AB-C#DE"
for char in code:
if char == "#":
break
if char == "-":
continue
print(char)
Output:
A
B
C
When char is the dash, continue runs. Python skips the print and moves straight on to C. When char is #, break runs and the loop ends. The loop never reaches D and E, so they are not printed.
You can also put one loop inside another (next lesson). In that case, break and continue affect only the inner loop, the one they are written in.
Use them for simple rules about when to stop and what to skip. If one loop has too many of them, it becomes hard to follow what the loop does.
In the exercise, stop the loop at a limit and skip multiples of 3.