0
for i in range(10): if i == 2: i += 2 print(i,end=",") 

I want to print 0,1,4,5,6,7,8,9 but it is printing 0,1,4,3,4,5,6,7,8,9. Is there any way to fix this??

1
  • 1
    Lookup continue Commented Oct 22, 2020 at 15:42

3 Answers 3

1

Use a while-loop:

i = 0 while i < 10: if i == 2: i += 2 print(i, end=",") i += 1 

The for for-loop will rebind the loop variable in each iteration. The while-loop gives you more control.

Sign up to request clarification or add additional context in comments.

Comments

0

This should do it:

for i in range(8): if i >= 2 : i += 2 print(i,end=",") 

Comments

0

Based on the overall logic, this might also do the trick.

for i in range(10): if i not in [2, 3]: print(i,end=",") 

Comments