代码之家  ›  专栏  ›  技术社区  ›  anish anil

“除非”值可以递增吗?[关闭]

  •  -4
  • anish anil  · 技术社区  · 6 年前

    unless 使用以下代码,将 x .

    x = 1
    unless x >= 2
      puts "x is less than 2"
    else
      puts "x is greater than 2"
      x = x + 1
    end
    

    输出为:

    x is less than 2
    

    除非 支持增量 ?

    1 回复  |  直到 6 年前
        1
  •  2
  •   sawa    6 年前

    你的问题不清楚。但是很明显,在代码中唯一增加变量的地方是:

    x = x + 1
    

    不执行,因为条件 unless x >= 2