PYTHON CORE · LESSON 26

Skip a step

Command continue · about 12 minutes

Learning with progressRead the summary for free. To save the work, log in to the account.
STEP 1

Skip just one lap

continue misses the rest of the current step, but the loop continues.

for n in range(4):
    if n == 2:
        continue
    print(n)

✦ There will be 0, 1 and 3.

STEP 2

Comparison with break

break stops the entire loop. continue only misses one value.

for n in range(3):
    if n == 1:
        continue
    print(n)

✦ After zero, the loop will reach two.

IN-CLASS PRACTICE

Type the code yourself

Reprint the example with the missing number.

for n in range(5):
    if n == 2:
        continue
    print(n)
Open the editor for class work
HOMEWORK

Solve it yourself

Using for n in range(5), output the numbers by running 3 through continue. The remaining numbers should appear.

The answer is hidden. Use similar examples from the lesson notes.

Opening up your homework