代码之家  ›  专栏  ›  技术社区  ›  Tim

这个代码示例中的逗号是什么?

  •  1
  • Tim  · 技术社区  · 16 年前
    cash = 100_000.00
    sum = 0
    cash += 1.00, sum while cash < 1_000_000.00 # underscores ignored
    

    syntax error, unexpected ',', expecting $end
    

    #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!
    
    5 回复  |  直到 16 年前
        1
  •  5
  •   Pesto    16 年前

    unconfirmed error report 关于它,但里面什么都没有 official errata

        2
  •  2
  •   jshen    16 年前

    i = 0
    puts i +=1 while i < 10
    

    这意味着这段代码是有意义的

    cash += 1.00 while cash < 1_000_000.00
    
        3
  •  0
  •   TravisO    16 年前

        4
  •  0
  •   Brian    16 年前

        5
  •  0
  •   Sparr    16 年前

    全文如下:

    此外,与if一样,您可以在末尾使用while作为语句修饰符 一个声明:

    cash = 100_000.00
    sum = 0
    
    cash += 1.00, sum while cash < 1_000_000.00 # underscores ignored
    

    所以现金一直在增加,直到它等于1000000.00美元。我喜欢!