为什么两个while循环在Python中一个接一个地循环(不在另一个中)不起作用?

cra*_*ice 0 python while-loop control-flow

我编写了下面的代码,我期待的是,当第一个循环结束并且不返回False时,流程将跟随第二个while循环.但是,流会跳过第二个while循环,只返回True.这是为什么?如何解决这个问题,使第一个while循环后的流程进入第二个while循环?

square = [[1,2,3,4],[4,3,1,4],[3,1,2,4],[2,4,4,3]]
# this is an auxiliary function
def getSum(lis):
sum = 0
for e in lis:        
    sum = sum + e
return sum

# here is where the problem is
def check_game(square):
standardSum = getSum(range(1, len(square)+1))    

while square: #this is the first while loop
    row = square.pop()
    print row, 'row', 'sum of row=', getSum(row)
    if standardSum != getSum(row):
        return False
m = 0
while m < len(square): # the second while loop, which the flow skips 
    n = 0
    col = []
    while n < len(square):
        col.append(square[n][m])
        n = n + 1
    print col, 'column'
    if standardSum != getSum(col):
        print standardSum, ' and sum of col =', getSum(col)
        return False            
    m = m + 1
return True 
Run Code Online (Sandbox Code Playgroud)

Sve*_*ach 5

第一个循环仅在没有剩余项目时终止square.在第一个循环之后,len(square)将是0,所以第二个循环的进入条件m < len(square)将是False.