2013-05-18 38 views
-1

我使用的問題here代碼。我收到以下錯誤,

Example test : example1 - RUNTIME ERROR (tested program terminated unexpectedly) 
Output: 
user.rb:113: syntax error, unexpected $end, expecting keyword_end 

example2 - RUNTIME ERROR (tested program terminated unexpectedly) 
Output: 
user.rb:113: syntax error, unexpected $end, expecting keyword_end 

example_grouped - RUNTIME ERROR (tested program terminated unexpectedly) 
Output: 
user.rb:113: syntax error, unexpected $end, expecting keyword_end 

下面是代碼,

def check_triangle (_array) 
    for p in 0 .. _array.length-1 
    for q in p .. _array.length-1 
     for r in q .. _array.length-1 
     return true if _array[p] + _array[q] > _array[r] && _array[p] + _array[r] > _array[q] && _array[r] + _array[q] > _array[p] 
     end 
    end 
    end 

    return false 
end 
+2

爲什麼你使用'for'而不是'each'?看到這很不尋常。儘管你粘貼的是有效的Ruby。據我所知,沒有任何錯誤。 – tadman

+2

這不能是真正的代碼。真實的代碼有113行。這個問題是由你沒有透露的行引起的。 – matt

回答

4
unexpected $end, expecting keyword_end 

這意味着分析器到達文件($end)結束,而查找的關鍵字end。換句話說,你錯過了end,可能是你的class。你還沒有發佈足夠的代碼來確認。

相關問題