链接的 for 循环不会增加计数器的值

时间:2021-03-17 06:42:20

标签: python loops for-loop

所以基本上我在另一个 for 循环中有一个 for 循环来遍历代表 Excel 工作表行的两个列表。然而,问题是,第二个 for 循环不会增加计数器的值(示例中的 current_row2)。如果我更改循环的排列(首先增加 current_row2,然后使用 current_row1 遍历另一张纸),那么现在不起作用的循环可以工作,反之亦然。 几行之后,我有另一个 for 循环来遍历工作表的列。这个循环工作得很好。 我也尝试将 for 循环与 range(max_rows) 一起使用,但它也不起作用。

有人可以帮助我为什么会出现问题以及如何解决吗?

#row_list_ascending_no_doubles 1/2 / col_list... = [0,1,2,..,max_row1/2/col]
#signal_col is a constant value that represents the column with where i want to compare the values in
for current_row1 in row_list_ascending_no_doubles1:
    temp1 = str(df1.iloc[current_row1,signal_col1])
    for current_row2 in range(ro2):
        temp2 = str(df2.iloc[current_row2,signal_col2])
        if temp1 == temp2:
            for current_col in col_list_ascending_no_doubles:
                temp2 = str(df2.iloc[current_row2,current_col])
                temp1 = str(df1.iloc[current_row1,current_col])

                if temp1 == temp2:
                    print('cell equal')
                else:
                    print('not equal')
        break   

1 个答案:

答案 0 :(得分:0)

看起来您的代码在任何事情发生之前就中断了。 else 之后没有 if temp1 == temp2 语句,因此它将命中 break 并停止运行第二个 for 循环。

相关问题