我正在阅读Chris Pine的https://github.com/neo4j/neo4j-ogm,我在Learn to Program中遇到了这个奇怪的代码段:
def doUntilFalse firstInput, someProc
input = firstInput
output = firstInput
while output
input = output
output = someProc.call input
end
input
end
buildArrayOfSquares = Proc.new do |array|
lastNumber = array.last
if lastNumber <= 0
false
else
array.pop # Take off the last number...
array.push lastNumber*lastNumber # ...and replace it with its square...
array.push lastNumber-1 # ...followed by the next smaller number.
end
end
在上面的while循环中检查的条件是什么?它似乎不是while output == true
的缩写。
答案 0 :(得分:2)
while output
表示运行循环,直到有false
或nil
以外的任何值。就像在Ruby中一样,除了这两个之外,一切都是真正的价值。