Home › Python › Python Loops

Python Loops

Last updated: 28 Sep 2026

Use for to go through a sequence and while to repeat on a condition.

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

n = 3
while n > 0:
    print(n)
    n -= 1