0 of 6 problems solved • 0%

Repetition

6 exercisesEasy

Use a for loop to visit values in a list or a range. Use a while loop when the next step depends on the current state.

for stop in ["Elm", "Pine"]: print(stop) seconds = 7 while seconds > 0: print(seconds) seconds -= 3

The first loop visits two named stops. The second prints 7, 4, and 1. Once the countdown reaches -2, its condition is false and the loop ends.