Reputation: 933
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
Upvotes: 3
Views: 2080
Reputation: 103
Use continue
for i in range(10):
if i == 5:
continue
print(i)
output:
0
1
2
3
4
6
7
8
9
Upvotes: 4
Reputation: 311143
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
Upvotes: 1