Skip to content

Note 05: Loops

Loops repeat work. Use them when the same pattern should happen multiple times.

Counting Loop

for number in range(1, 6):
    print(number)

Condition-Controlled Loop

total = 0
value = int(input("Enter a positive number, or 0 to stop: "))

while value != 0:
    total += value
    value = int(input("Enter a positive number, or 0 to stop: "))

print("Total:", total)

Loop Questions

  • What changes each time through the loop?
  • What condition eventually stops it?
  • Which variables accumulate information?