If statement 为什么这个方法调用工作,但不在代码中?

If statement 为什么这个方法调用工作,但不在代码中?,if-statement,methods,groovy,while-loop,If Statement,Methods,Groovy,While Loop,因此,在这个方法中,while循环的条件是我选择作为行内代码删除并创建一个在需要时调用的方法。但是,第一种方法不起作用,导致应用程序以静默方式锁定 def getLineRows( rows, index ) { def lineRows = [rows[index]] def newOperator def i = index + 1 if ( index <= ( rows.size() - 1 ) ) { newOperator = f

因此,在这个方法中,while循环的条件是我选择作为行内代码删除并创建一个在需要时调用的方法。但是,第一种方法不起作用,导致应用程序以静默方式锁定

def getLineRows( rows, index ) {
    def lineRows = [rows[index]]
    def newOperator
    def i = index + 1
    if ( index <= ( rows.size() - 1 ) ) {
        newOperator = false
这就是问题中的代码

        while ( index <= ( rows.size() - 1 ) && !newOperator ) {
            if ( rows[index].PGM_PROC_OPE.trim() == "" ||
                ( rows[index].PGM_PROC_TY == "OR" ||
                  rows[index].PGM_PROC_TY == "AN" ) ) {
                lineRows << rows[i]
            } else {
                newOperator = true
            }
            i++
        }
    }
    return lineRows
}
在第二个方法中,也是视觉上完全相同的方法中,我只是创建了一个名为moreRowsrows,index的方法。还有另外两个方法调用,但是通过测试,它们已被排除在考虑之外

def moreRows( rows, index ) {
    return index <= ( rows.size() - 1 )
}
当使用moreRows时,是什么导致下面的代码正常工作,而不是使用上面的moreRows所在的方法

def getLineRows( rows, index ) {
    def lineRows = [rows[index]]
    def newOperator
    def i = index + 1
    if ( moreRows( rows, i ) ) {
        newOperator = false
        while ( moreRows( rows, i ) && !newOperator ) {
            if ( operatorEmpty( rows, i ) || isSpecialProcType( rows, i ) ) {
                lineRows << rows[i]
            } else {
                newOperator = true
            }
            i++
        }
    }
    return lineRows
}
在循环中定义i并递增它,但不要在while语句中使用它

while ( index <= ( rows.size() - 1 ) && !newOperator ) {

所以你在这里进入了一个无限循环。

谢谢,就是这样。当我将代码从方法切换到内联时,我没有注意到我需要与I而不是索引进行比较。谢谢