Ram

Lesson 4 of 6

Loops

Repeat work with for and while loops.

Loops are useful when the same operation needs to run repeatedly.

Use a for loop when iterating over a collection or known range, and a while loop when repetition depends on a condition.

Example

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

Practice challenge

Print the even numbers from 2 through 10.

Previous
Next