Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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??
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.
Add a comment
This should do it:
for i in range(8): if i >= 2 : i += 2 print(i,end=",")
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=",")