gpt4 book ai didi

python,如何在范围循环中跳过行

转载 作者:行者123 更新时间:2023-11-30 22:00:37 26 4
gpt4 key购买 nike

在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

最佳答案

使用继续

for i in range(10):
if i == 5:
continue
print(i)

输出:

 0
1
2
3
4
6
7
8
9

关于python,如何在范围循环中跳过行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54271411/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com