【问题标题】:Ruby - negative condition in while statementRuby - while 语句中的否定条件
【发布时间】:2014-07-27 12:22:18
【问题描述】:

RubyMine 警告我这里的负面情况:

while !open_socket do
    sleep 1
end

我知道unlessif 的反义词,但while 的反义词是什么?

【问题讨论】:

    标签: ruby while-loop conditional-statements


    【解决方案1】:

    until

    until open_socket do
        sleep 1
    end
    

    如果只有一行,也可以写成:

    sleep 1 until open_socket
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-01
      • 2011-10-23
      • 2021-11-07
      • 1970-01-01
      • 1970-01-01
      • 2016-02-20
      • 1970-01-01
      相关资源
      最近更新 更多