【发布时间】:2021-11-02 04:24:08
【问题描述】:
如何重复 for 循环的索引?
for path in directory:
...
if ...:
stop here and
repeat the current index of the for loop
...
我称之为重启^^
【问题讨论】:
-
您正在寻找的概念是
redo,它是 Perl 和 Ruby 中的关键字,可以满足您的需求。不幸的是,Python 没有等效的功能。 -
你需要一个 do-while 循环,遗憾的是,它在 Python 中也不存在。因此,将其替换为
while循环:X; while condition: X。
标签: python loops for-loop indexing