Decreasing loop with continue
The loop in Listing 1 uses continue before its print statement.
for loop with continue (Question 1).
What does the code print?
- 4, 2, 0
- 4, 2, 0, -2
- Nothing is printed.
- 4, 2, 0, -2, -4
TipHint
The continue statement skips the rest of the current loop iteration and moves to the next value.
range(start, stop, step)supplies integers fromstarttoward, but excluding,stop.stepdefaults to1, andrange(stop)starts at0.list(range(2, 7, 2))is[2, 4, 6];list(range(5, 1, -2))is[5, 3].- A range is empty when the step cannot reach the stop; a zero step raises
ValueError.
listcollects the supplied values in a new list.