Q:

Like while loops, how can I skip a step in a for loop?

I try to skip several steps in for loop like while loop.
In the while loop, the steps are adjusted to specific conditions as shown in the code below.
i = 0 
while i <10:
    if i == 3:
        i = 5
    else:
        print(i)
    i = i + 1
#result 0 1 2 6 7 8 9

However, I tried to adjust the steps of the for loop in the same way, but failed.
for i in range(10):
    if i == 3:
        i = 5
    else:
        print(i)
#result 0 1 2 4 5 6 7 8 9

Can't I control step 'i' directly in a for loop?
If there is a way, let me know and I would appreciate it.

A:

Changing i in the loop body has no effect, as it will be automatically assigned the "next value in the range() result" on each iteration. You can instead use continue on values that you want to skip:
for i in range(10):
    if 3 <= i <= 5:
        continue
    else:
        print(i)

