gpt4 book ai didi

python - 在 Python 中重新启动当前迭代

转载 作者:太空宇宙 更新时间:2023-11-03 15:03:15 24 4
gpt4 key购买 nike

testing12(bad_order, order) == True 时,我想重新启动第一个 for 循环的当前迭代。我尝试使用 continue,但它跳过了迭代,这不是我想要的。

bad_order = []
order = []
for iteration in range(0, 10):

args = []
print("\n def test%d(self):" % (iteration))

for input in range(num_arguments):

args.append(pick_type())
order = args

if testing12(bad_order, order) == True:
continue

try:
result = target(*args)
code = test_to_string(target, args, result)

except Exception as error:
bad_order = args
code = test_to_string_exc(target, args, error)

最佳答案

您可以添加一个内部 while 循环,它实际上会重复外部循环迭代,直到它退出。如果您可以将重复条件放在 while 测试中,那么您就完成了:

for iteration in range(0, 10):
while some_condition:
...

如果不是,你可以使用一个while True循环,在底部放置一个无条件的break,然后使用一个continue来重复:

for iteration in range(0, 10):
while True:
...
if continue_condition:
continue
...
break

关于python - 在 Python 中重新启动当前迭代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35602700/

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