+ 3
for loops
consider the loop for a in range(10): # some code I cannot change the value of a while the loop is still running, e.g. for a in range(10): if a == 5: a += 1 is there any way of doing this without using a while loop instead (example below)? a = 0 while a < 10: if a == 5: a += 1 # doesn't generate an error
3 Answers
+ 2
right... that would only allow for incrementing the value of a by 1 though. if I wanted a -= 1, that wouldn't work.
+ 2
it's just less elegant, idk. but thanks anyways
0
Instead of a+=1 or a++ use âcontinueâ to skip to next index without doing anything . Found via Google.