在python语言中,我希望在不中断循环的情况下跳过range循环(或xrange)中的行,如下所示:
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发布于 2019-01-20 05:16:38
使用continue
for i in range(10):
if i == 5:
continue
print(i)输出:
0
1
2
3
4
6
7
8
9发布于 2019-01-20 05:14:19
您可以将该块嵌套在一个条件中:
for i in range(10):
... some code happening
... some code happening
if not some_statement:
... some code happening
... some code happeninghttps://stackoverflow.com/questions/54271411
复制相似问题