简体   繁体   English

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

[英]linked for loop doesn't increase the value of the counter

So basically I have a for loop in another for loop to go through two lists representing the rows of an Excel sheet.所以基本上我有一个for循环在另一个for循环到go通过两个列表代表Excel表的行。 The problem however is, that the second for loop doesnt increase the value of the counter(current_row2 in the example).然而问题是,第二个 for 循环不会增加计数器的值(示例中的 current_row2)。 If i change the arrangement of the loops (increase current_row2 first and then go through the other sheet with current_row1) the one that didn't work now works and the other way around.如果我更改循环的排列(首先增加 current_row2,然后通过另一张带有 current_row1 的表格增加 go),那么现在不起作用的那个现在可以工作,反之亦然。 A few lines later i have another for loop to go through the columns of the Sheet.几行之后,我通过工作表的列有另一个到 go 的 for 循环。 This loop works just fine.这个循环工作得很好。 I also tried using the for loop with range(max_rows) but it didn't work either.我也尝试将 for 循环与 range(max_rows) 一起使用,但它也不起作用。

Can someone help me why the problem occurs and how to fix it?有人可以帮助我为什么会出现问题以及如何解决它?

#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   

It looks like your code breaks before anything can happen.看起来您的代码在任何事情发生之前就中断了。 There is no else statement after if temp1 == temp2 so it will hit the break and stop the second for loop from running. if temp1 == temp2之后没有else语句,因此它将break并停止第二个 for 循环的运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM