cash = 100_000.00
sum = 0
cash += 1.00, sum while cash < 1_000_000.00 # underscores ignored
Run Code Online (Sandbox Code Playgroud)
我在一本书"学习Ruby"中找到了上面的例子,但是使用Ruby 1.9它没有编译("解释"?)
syntax error, unexpected ',', expecting $end
Run Code Online (Sandbox Code Playgroud)
在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!
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
412 次 |
| 最近记录: |