[英]python, how to skip lines in a range loop
In python language, I want to skip lines of a range loop (or xrange) without breaking the loop, as illustrated below: 在python语言中,我想在不破坏循环的情况下跳过范围循环(或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
Use continue
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.