count = 1
while count <= 3:
print(count)Line-by-line explanation
- Count starts at 1.
- The condition remains True.
- Nothing changes count.
- The loop displays 1 forever. This example is intentionally broken.
for number in range(1, 4):
print(number)Line-by-line explanation
range(1, 4)produces 1, 2, and 3.- The ending value 4 is not included.
- The loop displays exactly three numbers.
If a program is stuck in a terminal, Ctrl + C usually asks it to stop.