在For循环中循环时,在计数器索引处跳回For循环

2024-04-24 11:47:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我在for循环中解析数据。当找到该项时,它将跳转到while循环并找到与其相关的项。在这个while循环中,我有一个计数器用于while循环中的迭代。当我回溯到For循环时,它希望从For循环的原始位置进行迭代。我试图跳过这些迭代,并开始等于计数器。你知道吗

我是新来的。如果我不够清楚,我很乐意回答任何问题。你知道吗

for x in range(0, 10):
    if b has been found
         x = counter    
    #find a
        #flag is true

    while flag true:
         #find b
           #flag is false
         #count iterations

Tags: 数据intrueforifis计数器range
1条回答
网友
1楼 · 发布于 2024-04-24 11:47:13

你愿意重组你的代码吗?我认为外部for循环作为while循环会更好:

x = 0
while x < 10:
    if b has been found
         x = counter    
    #find a
        #flag is true

    while flag true:
         #find b
           #flag is false
         #count iterations
    x += 1

这样,就可以更改循环中x的值。你知道吗

相关问题 更多 >