← All lessons

continue: skip a step

Sign in · Sign up

Lesson 3.4

continue skips the rest of the current step and moves on to the next one:

for i in range(5):
    if i == 0:
        continue
    print(i)

Zero is skipped, the other numbers are printed. The difference from break is short: break leaves the loop, continue leaves only the step.

Print the numbers from 1 to limit, skipping all skip values. limit and skip are set by the check.

Hint

continue skips the rest of the step and moves on to the next number.

The check is "if the number equals skip, skip it". All the other numbers are printed, including those bigger than skip.