【发布时间】:2009-03-12 19:00:21
【问题描述】:
cash = 100_000.00
sum = 0
cash += 1.00, sum while cash < 1_000_000.00 # underscores ignored
我在“Learning Ruby”一书中找到了上面的例子,但是使用 Ruby 1.9 它不能编译(“解释”?)
syntax error, unexpected ',', expecting $end
1.00 之后逗号应该做什么?
这是示例的完整上下文:
#Also, like if, you can use while as a statement modifier, at the end of a statement:
cash = 100_000.00
sum = 0
cash += 1.00, sum while cash < 1_000_000.00 # underscores ignored
#So cash just keeps adding up until it equals $1,000,000.00. I like that!
【问题讨论】: