In python language, I want to skip lines of a range loop (or xrange) without breaking the loop, as illustrated below:
for i in range(10):
... some code happening
... some code happening
if (some statement == True):
skip the next lines of the loop, but do not break the loop until finished
... some code happening
... some code happening
Use continue
for i in range(10):
if i == 5:
continue
print(i)
output:
0
1
2
3
4
6
7
8
9
You could just nest that block in a condition:
for i in range(10):
... some code happening
... some code happening
if not some_statement:
... some code happening
... some code happening
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With