for number in [1, 2, 3]:
if number == 2:
break
print(number)Line-by-line explanation
- The loop begins with 1.
- When number becomes 2, the condition is True.
breakends the loop.- Only 1 is displayed.
for number in [1, 2, 3]:
if number == 2:
continue
print(number)Line-by-line explanation
- The loop visits each number.
- For 2, continue skips the print line.
- The output contains 1 and 3.