Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby - negative condition in while statement

RubyMine warns me about negative condition here:

while !open_socket do
    sleep 1
end

I know that unless is an opposite to if, but what is the opposite to while ?

like image 857
Paul Avatar asked Jul 31 '26 12:07

Paul


1 Answers

There is until:

until open_socket do
    sleep 1
end

If there is only one line in it, you could also write as:

sleep 1 until open_socket
like image 173
xdazz Avatar answered Aug 02 '26 09:08

xdazz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!