Ruby - 在 while 语句中使用负条件

3
RubyMine在这里警告我负面条件:
while !open_socket do
    sleep 1
end

我知道unlessif的相反词,但while的相反词是什么?
1个回答

9

这里涉及到 until

until open_socket do
    sleep 1
end

如果只有一行,你也可以这样写:
sleep 1 until open_socket

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接