2013-02-17 125 views
-1

我寫的,可以是遞歸的方法,但返回值始終爲0,即使它有一個值在控制檯上的字符串:的AutoIt - 返回值始終爲0

Func hasItTheThing($s) 

$result = StringInStr(...,...) 
local $newstring 

$newstring = $s 

If NOT $result > 0 Then 

ConsoleWrite("newstring = " & $newstring & @CRLF) 
return $newstring 

Else 


$newstring = ;Fix something with the string 
hasItTheThing($newstring) 


EndIf 


EndFunc 

回答

1

此外,您的錯誤導致總是爲零的結果:IF的「Else」分支(如果NOT $ result> 0)沒有任何回報。所以當result> 0時,你的函數調用它自己,但是當它返回一個值時,它將被丟棄,函數繼續到出口,不返回任何東西。

的修復:

... 
Else 
    $newstring = ;Fix something with the string 
    return hasItTheThing($newstring) ; <== Added a "return" here 
EndIf 
EndFunc